home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / e / amigae21b.lha / Amiga_E_v2.1b / Docs / Reference.doc < prev    next >
Text File  |  1992-09-02  |  98KB  |  2,746 lines

  1.  
  2.         +-----------------------------------------------+
  3.         |                        |
  4.         |                 Amiga E v2.1b                 |
  5.         |          Compiler for The E Language          |
  6.         |           By Wouter van Oortmerssen           |
  7.         |                        |
  8.          |              Language Reference               |
  9.         |                        |
  10.         +-----------------------------------------------+
  11.  
  12. Contents:
  13.  
  14.      1. format
  15.         A. tabs,lf etc.
  16.         B. comments
  17.         C. identifiers and types
  18.      2. immediate values
  19.         A. decimal (1)
  20.         B. hexadecimal ($1)
  21.         C. binary (%1)
  22.         D. float (1.0)
  23.         E. character ("a")
  24.         F. strings ('bla')
  25.         G. lists ([1,2,3]) and typed lists
  26.      3. expressions
  27.         A. format
  28.         B. precedence and grouping
  29.         C. types of expressions
  30.         D. function calls
  31.      4. operators
  32.         A. math (+ - * /)
  33.         B. comparison (= <> > < >= <=)
  34.         C. logical and bitwise (AND OR)
  35.         D. unary (SIZEOF ` ^ {} ++ -- -)
  36.         E. triple (IF THEN ELSE)
  37.         F. structure (.)
  38.         G. array ([])
  39.         H. float operator (|)
  40.             I. assignments expressions (:=)
  41.         J. sequencing (BUT)
  42.      5. statements
  43.         A. format (;)
  44.         B. statement labels and gotos (JUMP)
  45.         C. assignment (:=)
  46.         D. assembly mnemonics
  47.         E. conditional statement (IF)
  48.         F. for-statement (FOR)
  49.         G. while-statement (WHILE)
  50.         H. repeat-statement (REPEAT)
  51.         I. loop-statement (LOOP)
  52.         J. select-case-statement (SELECT)
  53.         K. increase statement (INC/DEC)
  54.             L. void expressions (VOID)
  55.      6. function definitions and declarations
  56.         A. proc definition and arguments (PROC)
  57.         B. local and global definitions: scope (DEF)
  58.         C. endproc/return
  59.         D. the "main" function
  60.         E. built-in system variables
  61.      7. declaration of constants
  62.         A. const (CONST)
  63.         B. enumerations (ENUM)
  64.         C. sets (SET)
  65.         D. built-in constants
  66.      8. types
  67.         A. about the "type" system
  68.         B. the basic type (LONG/PTR)
  69.         C. the simple type (CHAR/INT/LONG)
  70.         D. the array type (ARRAY)
  71.         E. the complex type (STRING/LIST)
  72.         F. the compound type (OBJECT)
  73.         G. initialisation
  74.      9. built-in functions
  75.         A. io functions
  76.         B. strings and string functions
  77.         C. lists and list functions
  78.         D. intuition support functions
  79.         E. graphics support functions
  80.         F. system support functions
  81.         G. math and other functions
  82.         H. string and list linking functions
  83.     10. library functions and modules
  84.         A. built-in library calls
  85.         B. interfacing to the amiga system with the 2.04 modules
  86.         11. quoted expressions
  87.         A. quoting and scope
  88.         B. Eval()
  89.         C. built-in functions
  90.         12. floating point support
  91.         A. using floats and float operator overloading
  92.         B. float expressions and conversion
  93.     13. Exception handling
  94.         A. defining exception handlers (HANDLE/EXCEPT)
  95.         B. using the Raise() function
  96.         C. defining exceptions for built-in functions (RAISE/IF)
  97.         D. use of exception-ID's
  98.         14. OO programming
  99.     15. inline assembly
  100.         A. identifier sharing
  101.         B. the inline assembler compared to a macro assembler
  102.             C. ways using binary data (INCBIN/CHAR..)
  103.         D. OPT ASM
  104.     16. implementation issues
  105.         A. the OPT keyword
  106.         B. small/large model
  107.         C. stack organisation
  108.         D. hardcoded limits
  109.         E. error messages, warnings and the unreferenced check
  110.         F. compiler buffer organisation and allocation
  111.         G. a brief history
  112.  
  113.  
  114.  
  115.  
  116.  
  117. +---------------------------------------------------------------+
  118. |                           1. FORMAT                |
  119. +---------------------------------------------------------------+
  120.  
  121. 1A. tabs,lf etc.
  122. ----------------
  123. E-sources are pure ascii format files, with the linefeed <lf> and
  124. semicolon ";" being the separators for two statements. Statements
  125. that have particulary many arguments, separated by commas ",", may
  126. be spread over several lines by ending a line with a comma, thus
  127. ignoring the following <lf>.
  128. Any lexical element in a source code file may be separated from another
  129. by any number of spaces, tabs etc.
  130.  
  131. 1B. comments
  132. ------------
  133. comments may be placed anywhere in a source file where normally a space
  134. would have been correct. They start with '/*' and end with '*/'
  135. and may be nested infinitely.
  136.  
  137. 1C. identifiers and types
  138. -------------------------
  139. identifiers are strings that the programmer uses to denote certain
  140. objects, in most cases variables, or even keywords or function names
  141. predefined by the compiler. An identifier may consist of:
  142.  
  143. - upper and lowercase characters
  144. - "0" .. "9" (except as first character)
  145. - "_" (the underscore)
  146.  
  147. All characters are significant, but the compiler just looks at the
  148. first two to identify the type of identifier it is dealing with:
  149.  
  150. both uppercase:               - keyword like IF, PROC etc.
  151.                               - constant, like MAX_LENGTH
  152.                               - assembly mnemonic, like MOVE
  153. first lowercase:              - identifier of variable/label/object etc.
  154. first upper and second lower: - E system function like: WriteF()
  155.                               - library call: OpenWindow()
  156.  
  157. Note that all identifiers obey this syntax, for example:
  158. WBenchToFront() becomes WbenchToFront()
  159.  
  160.  
  161. +---------------------------------------------------------------+
  162. |                      2. IMMEDIATE VALUES            |
  163. +---------------------------------------------------------------+
  164.  
  165. Immediate values in E all evaluate to a 32bit result; the only
  166. difference among these values (A-G) is either their internal
  167. representation, or the fact that they return a pointer rather than
  168. a value.
  169.  
  170. 2A. decimal (1)
  171. ---------------
  172. A decimal value is a sequence of characters "0" .. "9", possibly
  173. preceded by a minus "-" sign to denote negative numbers.
  174. examples: 1, 100, -12, 1024
  175.  
  176. 2B. hexadecimal ($1)
  177. --------------------
  178. A hexadecimal value uses the additional characters "A" .. "F" (or
  179. "a" .. "f") and is preceded by a "$" character.
  180. Examples: $FC, $DFF180, -$ABCD
  181.  
  182. 2C. binary (%1)
  183. ---------------
  184. Binary numbers start with a "%" character and use only "1" and "0"
  185. to form a value.
  186. Examples: %111, %1010100001, -%10101
  187.  
  188. 2D. float (1.0)
  189. ---------------
  190. Floats differ only from normal decimal numbers in that they have
  191. a "." to separate their two parts. Either one may be omitted,
  192. not both. Note that floats have a different internal 32bit (FFP)
  193. representation. See chapter 12 for more information on floats.
  194. Examples: 3.14159, .1 (=0.1), 1. (=1.0)
  195.  
  196. 2E. character ("a")
  197. -------------------
  198. The value of a character (enclosed in double "" quotes) is their
  199. ascii value, i.e. "A" = 65. In E, character immediate values
  200. may be a short string up to 4 characters, for example "FORM",
  201. where the first character "F" will be the MSB of the 32bit
  202. representation, and "M" the LSB (least significant byte).
  203.  
  204. 2F. string ('bla')
  205. ------------------
  206. Strings are any ascii representation, enclosed in single '' quotes.
  207. The value of such a string is a pointer to the first character of it.
  208. More specific: 'bla' yields a 32bit pointer to a memory area where
  209. we find the bytes "b", "l" and "a". ALL strings in E are terminated
  210. by a zero 0 byte.
  211. Strings may contain format signs introduced by a slash "\", either
  212. to introduce characters to the string that are for some reason
  213. not displayable, or for use with string formatting functions
  214. like WriteF(), TextF() and StringF(), or kick2 Vprintf().
  215.  
  216. \n        a linefeed (ascii 10)
  217. \a or ''    an apostrophe ' (the one used for enclosing the string)
  218. \e        escape (ascii 27)
  219. \t        tab (ascii 9)
  220. \\        a backslash
  221. \0        a zero byte. Of rare use, as ALL strings are 0-terminated
  222. \b        a carriage return (ascii 13)
  223.  
  224. Additionally, when used with formatting functions:
  225.  
  226. \d    print a decimal number
  227. \h    print a hexadecimal
  228. \s    print a string
  229. \c    print a character
  230. \z    set fill byte to '0' character
  231. \l    format to left of field
  232. \r    format to right of field
  233.  
  234. Field specifiers may follow the \d,\h and \s codes:
  235.  
  236. [x]    specify exact field width x
  237. (x,y)    specify minimum x and maximum y (strings only)
  238.  
  239. Example: print a hexadecimal number with 8 positions and leading zeroes:
  240. WriteF('\z\h[8]\n',num)
  241.  
  242. A string may be extended over several lines by trailing them with a "+"
  243. sign and a <lf>:
  244.  
  245. 'this specifically long string ' +
  246. 'is separated over two lines'
  247.  
  248.  
  249. 2G. lists ([1,2,3]) and typed lists
  250. -----------------------------------
  251. An immediate list is the constant counterpart of the LIST datatype,
  252. just as a 'string' is the constant counterpart for the STRING or
  253. ARRAY OF CHAR datatype. Example:
  254.  
  255. [3,2,1,4]
  256.  
  257. is an expression that has as value a PTR to an already initialised list,
  258. a list as a representation in memory is compatible with an ARRAY OF LONG,
  259. with some extra length information at a negative offset. You may use these
  260. immediate lists anywhere a function expects a PTR to an array of
  261. 32bits values, or a list. Examples:
  262.  
  263. ['string',1.0,2.1]
  264. [WA_FLAGS,1,WA_IDCMP,$200,WA_WIDTH,120,WA_HEIGHT,150,TAG_DONE]
  265.  
  266. See the part on list-functions for a discussion on typed-immediate
  267. lists and detailed information.
  268.  
  269.  
  270.  
  271. +---------------------------------------------------------------+
  272. |                         3. EXPRESSIONS             |
  273. +---------------------------------------------------------------+
  274.  
  275. 3A. format
  276. ----------
  277. An expression is a piece of code held together by operators, functions
  278. and brackets to form a value.
  279. They mostly consist of:
  280.  
  281. - immediate values as discussed in chapter 2
  282. - operators as discussed in chapter 4
  283. - function calls as discussed in chapter 3D
  284. - brackets () as discussed in chapter 3B
  285. - variables or variable-expressions (see 3C)
  286.  
  287. examples of expressions:
  288. 1
  289. 'hello'
  290. $ABCD+(2*6)+Abs(a)
  291. (a<1) OR (b>=100)
  292.  
  293. 3B. precedence and grouping
  294. ---------------------------
  295. The E language has _no_ precedence whatsoever. This means that
  296. expressions are evaluated left to right. You may change
  297. precedence by bracketing some (sub-)expression:
  298. 1+2*3 /* =9 */     1+(2*3) /* =7 */       2*3+1  /* =7 */
  299.  
  300. 3C. types of expressions
  301. ------------------------
  302. There are three types of expressions that may be used for different
  303. purposes;
  304.  
  305. - <var>, consisting of just a variable
  306. - <varexp>, consisting of a variable, possibly with unary operators
  307.   with it, like ++ (increment) or [] (array operator). For those,
  308.   see chapter 4D and 4G. It denotes a modifiable expression, like
  309.   Lvalues in C.
  310.   Note that those (unary) operators are not part of any precedence.
  311. - <exp>. This includes <var> and <varexp>, and any other expression.
  312.  
  313. 3D. function calls
  314. ------------------
  315. A function call is a temporary suspension of the current code for a
  316. jump to a function, this may be either a self-written function (PROC),
  317. or a function provided by the system. The format of a function call
  318. is the name of the function, followed by two brackets () enclosing
  319. zero to unlimited arguments, separated by commas ",".
  320. Note that arguments to functions are again expressions.
  321. See chapter 6 on how to make your own functions, and chapters 9 and 10
  322. on built-in functions. Examples:
  323.  
  324. foo(1,2)
  325. Gadget(buffer,glist,2,0,40,80+offset,100,'Cancel')
  326. Close(handle)
  327.  
  328.  
  329. +---------------------------------------------------------------+
  330. |                          4. OPERATORS                |
  331. +---------------------------------------------------------------+
  332.  
  333. 4A. math (+ - * /)
  334. ------------------
  335. These infix operators combine an expression with another value
  336. to yield a new value. Examples:
  337.  
  338. 1+2, MAX-1*5
  339.  
  340. see chapter 12 on how to overload these operators for use with floats.
  341. "-" may be used as the first part of an expression, with an implied 0,
  342. i.e.    -a    or    -b+1      is legal.
  343. Note that * and / are by default 16bit operators: see Mul()
  344.  
  345. 4B. comparison (= <> > < >= <=)
  346. -------------------------------
  347. Equal to math operators, with the difference that they result in either
  348. TRUE (32bit value -1), or FALSE. These can also be overloaded for floats.
  349.  
  350. 4C. logical and bitwise (AND OR)
  351. --------------------------------
  352. These operators either combine truth values to new ones, or perform
  353. bitwise AND and OR operations. Examples:
  354. (a>1) AND ((b=2) OR (c>=3))         /* logical */
  355. a:=b AND $FF                        /* bitwise */
  356.  
  357. 4D. unary (SIZEOF ^ {} ++ -- `)
  358. ---------------------------------
  359. - SIZEOF <objectident>
  360.   simply returns the size of a certain object.
  361.   Example: SIZEOF newscreen
  362. - {<var>}
  363.   Returns the address of a variable or label. This is the operator
  364.   you would use to give a variable as argument to a function by
  365.   reference, instead of by value, which is default in E. See "^".
  366.   Example:  Val(input,{x})
  367. - ^<var>
  368.   The counterpart of {}, writes or reads variables that were given by
  369.   reference, examples:      ^a:=1     b:=^a
  370.   it may also be used to plainly "peek" or "poke" LONG values from
  371.   memory, if <var> is pointer to such a value.
  372.   Example for {} and ^: write your own assignment function;
  373.  
  374.   PROC set(var,exp)
  375.     ^var:=exp
  376.   ENDPROC
  377.  
  378.   and call it with:     set({a},1)     /* equals a:=1 */
  379. - <varexp>++   and  <varexp>--
  380.   Increases (++) or decreases (--) the pointer that is denoted by
  381.   <varexp> by the size of the data it points to. This has the effect
  382.   that that pointer points to the next or previous item. When used
  383.   on variables that are not pointers, these will simply be changed
  384.   by one. Note that ++ always takes effect _after_ the calculation
  385.   of <varexp>, -- always _before_. Examples:
  386.  
  387.   a++          /* return value of a, then increase by one */
  388.   sp[]--       /* decrease pointer sp by 4 (if it were an array of long),
  389.                   and read value pointed at by sp */
  390. - `<exp>
  391.   This is called a quoted expression, from LISP. <exp> is not evaluated,
  392.   but instead returns the address of the expression, which can later be
  393.   evaluated when required. More on this special feature in chapter 11
  394.  
  395. 4E. triple (IF THEN ELSE)
  396. -------------------------
  397. The IF operator has quite the same function as the IF statement, only
  398. it selects between two expressions instead of two statements or blocks
  399. of statements. It equals the x?y:z operator in C.
  400.  
  401. IF <boolexp> THEN <exp1> ELSE <exp2>
  402.  
  403. returns exp1 or exp2, according to boolexp. For example, instead of:
  404.  
  405. IF a<1 THEN b:=2 ELSE b:=3
  406. IF x=3 THEN WriteF('x is 3\n') ELSE WriteF('x is something else\n')
  407.  
  408. write:
  409.  
  410. b:=IF a<1 THEN 2 ELSE 3
  411. WriteF(IF x=3 THEN 'x is 3\n' ELSE 'x is something else\n')
  412.  
  413. 4F. structure (.)
  414. -----------------
  415. <ptr2object>.<memberofobject> builds a <varexp>
  416. The pointer has to be declared as PTR TO <object> or ARRAY OF <object>
  417. (see chapter 8 for these), and the member has to be a legal
  418. object identifier. Note that reading a subobject in an object this
  419. way results in a pointer to that object. Examples:
  420.  
  421. thistask.userdata:=1
  422. rast:=myscreen.rastport
  423.  
  424. 4G. array ([])
  425. --------------
  426. <var>[<indexexp>] (is a <varexp>)
  427. This operator reads the value from the array <var> points to, with
  428. index <indexexp>. The index may be just about any expression, with
  429. little limitations that it should not contain function calls and the like
  430. when used on the left-hand side of an assignment.
  431. Note1: "[]" is a shortcut for "[0]"
  432. Note2: with an array of n elements, the index may be  0 .. n-1
  433. Examples:
  434.  
  435. a[1]:=10           /* sets second element to 10 */
  436. x:=table[y*4+1]    /* reads from array */
  437.  
  438. 4H. float operator (|)
  439. ----------------------
  440. <exp>|<exp>
  441. Converts expressions from integer to float and back, and
  442. overloads operators + - * / = <> < > <= >= with float equivalents.
  443. See chapter 12 to read all about floats and this operator.
  444.  
  445. 4I. assignments expressions (:=)
  446. --------------------------------
  447. Assignments (setting a variable to a value) exist as statement
  448. and as expression. The only difference is that the statement
  449. version has the form <varexp>:=<exp> and the expression <var>:=<exp>.
  450. The latter has the value of <exp> as result.
  451. Note that as <var>:= takes on an expression, you will often need
  452. parentheses to force correct interpretation, like:
  453.  
  454. IF mem:=New(100)=NIL THEN error()
  455.  
  456. is interpreted like:
  457.  
  458. IF mem:=(New(100)=NIL) THEN error()
  459.  
  460. which is not what you mean: mem should be a pointer, not a boolean.
  461. but you should write:
  462.  
  463. IF (mem:=New(100))=NIL THEN error()
  464.  
  465. 4J. sequencing (BUT)
  466. --------------------
  467. The sequencing operator "BUT" allows two expressions to be written
  468. in a construction that allows for only one. Often in writing
  469. complex expressions/function calls, one would like to do a second
  470. thing on the spot, like an assignment. Syntax:
  471.  
  472. <exp1> BUT <exp1>
  473.  
  474. this says: evaluate exp1, but return the value of exp2.
  475. Example:
  476.  
  477. myfunc((x:=2) BUT x*x)
  478.  
  479. assign 2 to x and then calls myfunc with x*x. The () around the
  480. assignment are again needed to prevent the := operator from taking
  481. (2 BUT x*x) as an expression.
  482.  
  483.  
  484. +---------------------------------------------------------------+
  485. |                          5. STATEMENTS            |
  486. +---------------------------------------------------------------+
  487.  
  488.  
  489. 5A. format (;)
  490. --------------
  491. As suggested in chapter 1A, a statement generally stands in its
  492. own line, but several of them may be put together on one line
  493. by separating them with semicolon, or one may be spread over
  494. more than one line by ending each line in a comma ",". Examples:
  495.  
  496. a:=1; WriteF('hello!\n')
  497. DEF a,b,c,d,                      /* too many args for one line (faked) */
  498.     e,f,g
  499.  
  500. statements may be:
  501. - assignments
  502. - conditional statements, for statements and the like, see chapters 5E-5K
  503. - void expressions
  504. - labels
  505. - assembly instructions
  506.  
  507. The comma is the primary character to show that you do not wish to
  508. end the statement with the next linefeed, but the following characters
  509. also signal a continuation of a statement on the next line:
  510.  
  511. + - * /
  512. = > < <> >= <=
  513. AND OR BUT THEN
  514.  
  515.  
  516. 5B. statement labels and gotos (JUMP)
  517. -------------------------------------
  518. Labels are global-scoped identifiers with a ':' added to it, as in:
  519.  
  520. mylabel:
  521.  
  522. they may be used by instructions such as JUMP, and to reference
  523. static data. They may be used to jump out of all types of loops (although
  524. this technique is not encouraged), but not out of procedures.
  525. In normal E programs they are mostly used with inline assembly.
  526. Labels are always globally visible.
  527.  
  528. Usage of JUMP:    JUMP <label>
  529. continues execution at <label>. You are not encouraged to use this
  530. instruction, it's there for situations that would otherwise increase
  531. the complexity of the program. Example:
  532.  
  533. IF Mouse()=1 THEN JUMP stopnow
  534.  
  535. /* other parts of program */
  536.  
  537. stopnow:
  538.  
  539. 5C. assignment (:=)
  540. -------------------
  541. The basic format of an assignment is:   <var> := <exp>
  542. Examples: a:=1,  a:=myfunc(),  a:=b*3
  543.  
  544. 5D. assembly mnemonics
  545. ----------------------
  546. In E, inline assembly is a true part of the language, they need not
  547. be enclosed in special "ASM" blocks or the like, as is usual in
  548. other languages, nor are separate assemblers necessary to assemble
  549. the code. This also means that it obeys the E syntax rules, etc.
  550. See chapter 15 to read all about the inline assembler. Example:
  551.  
  552. DEF a,b
  553. b:=2
  554. MOVEQ  #1,D0             /* just use some assembly statements */
  555. MOVE.L D0,a              /* a:=1+b  */
  556. ADD.L  b,a
  557. WriteF('a=\d\n',a)       /* a will be 3 */
  558.  
  559. 5E. conditional statement (IF)
  560. ------------------------------
  561. IF, THEN, ELSE, ELSEIF, ENDIF
  562.  
  563. syntax:        IF <exp> THEN <statement> [ ELSE <statement> ]
  564. or:        IF <exp>
  565.                   <statements>
  566.         [ ELSEIF <exp>           /* multiple elseifs may occur */
  567.                   <statements> ]
  568.         [ ELSE ]
  569.                   <statements>
  570.         ENDIF
  571.  
  572. builds a conditional block. Note that there are two general forms of
  573. this statement, a single-line and a multiple-line version.
  574.  
  575. 5F. for-statement (FOR)
  576. -----------------------
  577. FOR, TO, STEP, DO, ENDFOR
  578.  
  579. syntax:        FOR <var> := <exp> TO <exp> STEP <step> DO <statement>
  580. or:        FOR <var> := <exp> TO <exp> STEP <step>
  581.                   <statements>
  582.         ENDFOR
  583. builds a for-block, note the two general forms. <step> may be
  584. any positive or negative constant, excluding 0. Example:
  585.  
  586. FOR a:=1 TO 10 DO WriteF('\d\n',a)
  587.  
  588. 5G. while-statement (WHILE)
  589. ---------------------------
  590. WHILE, DO, ENDWHILE
  591.  
  592. syntax:        WHILE <exp> DO <statement>
  593. or:        WHILE <exp>
  594.                   <statements>
  595.         ENDWHILE
  596. builds a while-loop, which is repeated as long as <exp> is TRUE. Note
  597. the one-line/one-statement version and the multiple line version.
  598.  
  599. 5H. repeat-statement (REPEAT)
  600. -----------------------------
  601. REPEAT, UNTIL
  602.  
  603. syntax:        REPEAT
  604.         UNTIL <exp>
  605. builds a repeat-until block: it will continue to loop this block until
  606. <exp>=TRUE. Example:
  607.  
  608. REPEAT
  609.   WriteF('Do you really, really wish to exit this program?\n')
  610.   ReadStr(stdout,s)
  611. UNTIL StrCmp(s,'yes please!')
  612.  
  613. 5I. loop-statement (LOOP)
  614. -------------------------
  615. LOOP, ENDLOOP
  616.  
  617. syntax:        LOOP
  618.           <statements>
  619.         ENDLOOP
  620. builds an infinite loop.
  621.  
  622.  
  623. 5J. select-case-statement (SELECT)
  624. ---------------------------------
  625. SELECT, CASE, DEFAULT, ENDSELECT
  626.  
  627. syntax:        SELECT <var>
  628.         [ CASE <exp>
  629.           <statements> ]
  630.         [ CASE <exp>
  631.           <statements> ]   /* any number of these blocks */
  632.         [ DEFAULT
  633.           <statements> ]
  634.         ENDSELECT
  635. builds a select-case block. Various expressions will be matched against
  636. the variable, and only the first matching block executed. If nothing matches,
  637. a default block may be executed.
  638.  
  639. SELECT character
  640.   CASE 10
  641.     WriteF('Gee, I just found a linefeed\n')
  642.   CASE 9
  643.     WriteF('Wow, this must be a tab!\n')
  644.   DEFAULT
  645.     WriteF('Do you know this one: \c ?\n',character)
  646. ENDSELECT
  647.  
  648. 5K. increase statement (INC/DEC)
  649. --------------------------------
  650. INC, DEC
  651.  
  652. syntax:        INC <var>
  653.         DEC <var>
  654. short for <var>:=<var>+1 and <var>:=<var>-1. Only difference with
  655. var++ and var-- is that these are statements, and do not return a value,
  656. and are thus more optimal.
  657.  
  658. 5L. void expressions (VOID)
  659. ---------------------------
  660. VOID
  661.  
  662. syntax:        VOID <exp>
  663. calculates the expression without the result going anywhere. Only useful
  664. for a clearer syntax, as expressions may be used as statements without
  665. VOID in E anyway. This may cause subtle bugs though, as "a:=1" assigns
  666. a the value 1, but "a=1" as a statement will do nothing. E will give you
  667. a warning if this happens.
  668.  
  669.  
  670. +---------------------------------------------------------------+
  671. |            6. FUNCTION DEFINITIONS AND DECLARATIONS        |
  672. +---------------------------------------------------------------+
  673.  
  674. 6A. proc definition and arguments (PROC)
  675. ----------------------------------------
  676.  
  677. You may use PROC and ENDPROC to collect statements into your own functions.
  678. Such a function may have any number of arguments, and one return value.
  679.  
  680. PROC, ENDPROC
  681.  
  682. syntax:        PROC <label> ( <args> , ... )
  683.         ENDPROC <returnvalue>
  684. defines a procedure with any number of arguments. Arguments are of type LONG
  685. or optionally of type PTR TO <type> (see chapter 8) and need no further
  686. declaration. The end of a procedure is designated by ENDPROC. If no
  687. return value is given, 0 is returned. Example: write a function that
  688. returns the sum of two arguments:
  689.  
  690. PROC add(x,y)         /* x and y are local variables */
  691. ENDPROC x+y           /* return the result  */
  692.  
  693. 6B. local and global definitions: scope (DEF)
  694. ---------------------------------------------
  695. You may define additional local variables besides those which are
  696. arguments with the DEF statement. The easiest way is simply like:
  697.  
  698. DEF a,b,c
  699.  
  700. declares the identifiers a, b and c as variables of your function.
  701. Note that such declarations should be at the start of your function.
  702.  
  703. DEF
  704.  
  705. syntax:        DEF <declarations>,...
  706. description:    declares variables. A declaration has one of the forms:
  707.         <var>
  708.         <var>:<type>              where <type>=LONG,<objectident>
  709.         <var>[<size>]:<type>      where <type>=ARRAY,STRING,LIST
  710.  
  711. See chapter 8 for more examples, as that is where the types are introduced.
  712. For now, we'll use the <var> form.
  713. Arguments to functions are restricted to basic types; see chapter 8B.
  714. A declaration of a basic type can have an initialisation, in the current
  715. version this must be an integer (not an expression):
  716.  
  717. DEF a=1,b=2
  718.  
  719.  
  720. A program consists of a set of functions, called procedures, PROCs. Each
  721. procedure may have Local variables, and the program as a whole may have
  722. Global variables. At least one procedure should be the PROC main(), as
  723. this is the module where execution begins. A simple program could look like:
  724.  
  725. DEF a, b                            /* definition of global vars */
  726.  
  727. PROC main()                         /* all functions in random order */
  728.   bla(1)
  729. ENDPROC
  730.  
  731. PROC bla(x)
  732.   DEF y,z                           /* possibly with own local vars */
  733. ENDPROC
  734.  
  735. To summarize, local definitions are the ones you make at the start of
  736. procedures, and which are only visible within that function. Global
  737. definitions are made before the first PROC, at the start of your
  738. source code, and they are globally visible. Global and local variables
  739. (and of course local variables of two different functions) may have the
  740. same name, local variables always have priority.
  741.  
  742. 6C. endproc/return
  743. ------------------
  744. As stated before, ENDPROC marks the end of a function definition, and may
  745. return a value. Optionally RETURN may be used at any point in the function
  746. to exit, if used in main(), it will exit the program. See also CleanUp()
  747. in chapter 9F.
  748.  
  749. RETURN [<returnvalue>]          /* optional */
  750.  
  751. Example:
  752.  
  753. PROC getresources()
  754.   /* ... */
  755.   IF error THEN RETURN FALSE  /* something went wrong, so exit and fail */
  756.   /* ... */
  757. ENDPROC TRUE   /* we got this far, so return TRUE */
  758.  
  759. a very short version of a function definition is:
  760.  
  761. PROC <label> ( <arg> , ... ) RETURN <exp>
  762.  
  763. These are function definitions that only make small computations, like
  764. faculty functions and the like:  (one-liners :-)
  765.  
  766. PROC fac(n) RETURN IF n=1 THEN 1 ELSE fac(n-1)*n
  767.  
  768.  
  769. 6D. the "main" function
  770. -----------------------
  771. The PROC called main is only of importance because it is called as first
  772. function; it behaves exactly the same as other functions, and may also
  773. have local variables. Main has no arguments: the command-line arguments
  774. are supplied in the system-variable "arg", or can be checked with
  775. ReadArgs()
  776.  
  777. 6E. built-in system variables
  778. ----------------------------
  779. Following global variables are always available in you program,
  780. they're called system variables.
  781.  
  782. arg        As discussed above, contains a pointer to a zero-terminated
  783.         string, containing the command-line arguments. Don't use this
  784.         variable if you wish to use ReadArgs() instead.
  785. stdout        Contains a file-handle to the standard output (and input).
  786.         If your program was started from the workbench, so no
  787.         shell-output is available, WriteF() will open a
  788.         CON: window for you and put its file handle here.
  789. conout        This is where that file handle is kept, and the console
  790.         window will be automatically closed upon exit of your
  791.         program. See WriteF() in section 9A on how to use these
  792.         two variables properly.
  793. execbase,    These five variables are always provided with their
  794. dosbase,    correct values.
  795. gfxbase,
  796. intuitionbase,
  797. mathbase
  798. stdrast        Pointer to standard rastport in use with your program,
  799.         or NIL. The built-in graphics functions like Line()
  800.         make use of this variable.
  801. wbmessage    Contains a ptr to a message you got if you started
  802.         from wb, else NIL. May be used as a boolean to detect
  803.         if you started from workbench, or even check any
  804.         arguments that were shift-selected with your icon.
  805.         See WbArgs.e in the sources/examples dir how to
  806.         make good use of wbmessage.
  807.  
  808.  
  809. +---------------------------------------------------------------+
  810. |                  7. DECLARATION OF CONSTANTS            |
  811. +---------------------------------------------------------------+
  812.  
  813. 7A. const (CONST)
  814. -----------------
  815.  
  816. syntax:        CONST <declarations>,...
  817. Enables you to declare a constant. A declaration looks like:
  818. <ident>=<value>
  819. constants must be uppercase, and will in the rest of the program be
  820. treated as <value>. Example:
  821.  
  822. CONST MAX_LINES=100, ER_NOMEM=1, ER_NOFILE=2
  823.  
  824. You cannot declare constansts in terms of others that are being
  825. declared in the same CONST statement: put these in the next.
  826.  
  827. 7B. enumerations (ENUM)
  828. -----------------------
  829. Enumerations are a specific type of constant that need not be given values,
  830. as they simply range from 0 .. n, the first being 0. At any given point
  831. in an enumeration, you may use the '=<value>' notation to set or reset
  832. the counter value. Example:
  833.  
  834. ENUM ZERO, ONE, TWO, THREE, MONDAY=1, TUESDAY, WEDNESDAY
  835.  
  836. ENUM ER_NOFILE=100, ER_NOMEM, ER_NOWINDOW
  837.  
  838. 7C. sets (SET)
  839. --------------
  840. Sets are again like enumerations, with the difference that instead of
  841. increasing a value (0,1,2,...) they increase a bitnumber (0,1,2,...) and
  842. thus have values like (1,2,4,8,...). This has the added advantage that
  843. they may be used as sets of flags, as the keyword says.
  844. Suppose a set like the one below to describe properties of a window:
  845.  
  846. SET SIZEGAD,CLOSEGAD,SCROLLBAR,DEPTH
  847.  
  848. to initialise a variable to properties DEPTH and SIZEGAD:
  849.  
  850. winflags:=DEPTH OR SIZEGAD
  851.  
  852. to set an additional SCROLLBAR flag:
  853.  
  854. winflags:=winflags OR SCROLLBAR
  855.  
  856. and to test if two properties hold:
  857.  
  858. IF winflags AND (SCROLLBAR OR DEPTH) THEN /* ... */
  859.  
  860.  
  861. 7D. built-in constants
  862. ---------------------
  863. Following are built-in constants that may be used:
  864.  
  865. TRUE,FALSE    Represent the boolean values (-1,0)
  866. NIL        (=0), the uninitialised pointer.
  867. ALL        Used with string functions like StrCopy() to copy all characters
  868. GADGETSIZE    Minimum size in bytes to hold one gadget; see Gadget() in 9D
  869. OLDFILE,NEWFILE    Mode-parameters for use with Open()
  870. STRLEN        Always has the value of the length of the last immediate
  871.         string used. Example:
  872.  
  873.         Write(handle,'hi folks!',STRLEN)      /* =9 */
  874.  
  875.  
  876.  
  877. +---------------------------------------------------------------+
  878. |                           8. TYPES                |
  879. +---------------------------------------------------------------+
  880.  
  881. 8A. about the "type" system
  882. ---------------------------
  883. E doesn't have a rigid type-system like Pascal or Modula2, it's even more
  884. flexible than C's type system: you might as well call it a datatype-system.
  885. This goes hand in hand with the philosophy that in E all datatypes are
  886. equal: all basic small values like characters, integers etc. All have
  887. the same 32bit size, and all other datatypes like arrays and strings
  888. are represented by 32bit pointers to them. This way, the e compiler can
  889. generate code in a very polymorphic way.
  890. The (dis)advantages are obvious:
  891.  
  892. disadvantages of the E-type system
  893. - less compiler checking on silly errors you make
  894.  
  895. advantages:
  896. - low-level polymorphism
  897. - flexible way of programming: no problem that some types of return values
  898.   don't match, no superfluous "casts" etc.
  899. - no hard to find errors when mixing data of different sizes in expressions
  900. - still benefit of self-documenting types, if you wish, like:
  901.  
  902.   PTR to newscreen
  903.  
  904.  
  905. 8B. the basic type (LONG/PTR)
  906. -----------------------------
  907. There's only one basic, non-complex variable type in E, which is the
  908. 32bit type LONG. As this is the default type, it may be declared as:
  909.  
  910. DEF a:LONG             or just:            DEF a
  911.  
  912. This variable type may hold what's known as CHAR/INT/PTR/LONG types in other
  913. languages. A special variation of LONG is the PTR type. This type
  914. is compatible with LONG, with the only difference that it specifies
  915. to what type it is a pointer. By default, the type LONG is specified
  916. as PTR TO CHAR. Syntax:
  917.  
  918. DEF <var>:PTR TO <type>
  919.  
  920. where type is either a simple type or a compound type. Example:
  921.  
  922. DEF x:PTR TO INT, myscreen:PTR TO screen
  923.  
  924. Note that 'screen' is the name of an object as defined in intuition/screens.m
  925. For example, if you open your own screen with:
  926.  
  927. myscreen:=OpenS(...   etc.
  928.  
  929. you may use the pointer myscreen as in 'myscreen.rastport'. However,
  930. if you do not wish to do anything with the variable until you call
  931. CloseS(myscreen), you may simply declare it as
  932.  
  933. DEF myscreen
  934.  
  935.  
  936. 8C. the simple type (CHAR/INT/LONG)
  937. -----------------------------------
  938. The simple types CHAR (8bit) and INT (16bit) may not be used as types
  939. for a basic (single) variable; the reason for this must be clear by now.
  940. However they may be used as data type to build ARRAYs from, set PTRs to,
  941. use in the definition of OBJECTs etc. See those for examples.
  942.  
  943.  
  944. 8D. the array type (ARRAY)
  945. --------------------------
  946. ARRAYs are declared by specifying their length (in bytes):
  947.  
  948. DEF b[100]:ARRAY
  949.  
  950. this defines an array of 100 bytes. Internally, 'b' is a variable of
  951. type LONG and a PTR to this memory area.
  952. Default type of an array-element is CHAR, it may be anything by specifying:
  953.  
  954. DEF x[100]:ARRAY OF LONG
  955. DEF mymenus[10]:ARRAY OF newmenu
  956.  
  957. where "newmenu" is an example of a structure, called OBJECTs in E.
  958. Array access is very easy with:   <var>[<sexp>]
  959.  
  960. b[1]:="a"
  961. z:=mymenus[a+1].mutualexclude
  962.  
  963. Note that the index of an array of size n ranges from 0 to n-1,
  964. and not from 1 to n.
  965. Note that ARRAY OF <type> is compatible with PTR TO <type>, with the
  966. only difference that the variable that is an ARRAY is already
  967. initialised.
  968.  
  969.  
  970. 8E. the complex type (STRING/LIST)
  971. ----------------------------------
  972. - STRINGs. Similar to arrays, but different in the respect that they may
  973.   only be changed by using E string functions, and that they contain
  974.   length and maxlength information, so string functions may alter them in a
  975.   safe fashion, i.e: the string can never grow bigger than the memory
  976.   area it is in. Definition:
  977.  
  978.   DEF s[80]:STRING
  979.  
  980.   The STRING datatype is backwards compatible with PTR TO CHAR and
  981.   of course ARRAY OF CHAR, but not the other way around.
  982.   See the section on string functions for more details.
  983.  
  984. - LISTs. This is a datatype not found in other procedural languages, it
  985.   is something found in languages like ProLog and Lisp. The E version
  986.   may be interpreted as a mix between a STRING and an ARRAY OF LONG.
  987.   I.e: this data structure holds a list of LONG variables which may be
  988.   extended and shortened as STRINGs. Definition:
  989.  
  990.   DEF x[100]:LIST
  991.  
  992.   A powerful addition to this datatype is that it also has a 'constant'
  993.   equivalent [], like STRINGs have ''. LIST is backward compatible with
  994.   PTR TO LONG and of course ARRAY OF LONG, but not the other way around.
  995.   See chapters 2G and 9C for more on this.
  996.  
  997.  
  998. 8F. the compound type (OBJECT)
  999. ------------------------------
  1000.   OBJECTs are much like a struct in C or a RECORD in pascal. Example:
  1001.  
  1002.   OBJECT myobj
  1003.     a:LONG
  1004.     b:CHAR
  1005.     c:INT
  1006.   ENDOBJECT
  1007.  
  1008.   This defines a data structure consisting of three elements. Syntax:
  1009.  
  1010.   OBJECT <objname>
  1011.     <membername> [ : <type> ]           /* any number of these */
  1012.   ENDOBJECT
  1013.  
  1014.   where type is a simple or again a compound type, or a simple
  1015.   array type, i.e  [<numelements>]:ARRAY with the default CHAR size for
  1016.   an element. Note that <membername> need not be a unique identifier,
  1017.   it may be in other objects too. There are lots of ways to use objects:
  1018.  
  1019.   DEF x:myobj                      /* x is a structure */
  1020.   DEF y:PTR TO myobj               /* y is just a pointer to it */
  1021.   DEF z[10]:ARRAY OF myobj
  1022.  
  1023.   y:=[-1,"a",100]:myobj            /* typed lists */
  1024.  
  1025.   IF y.b="a" THEN /* ... */
  1026.  
  1027.   z[4].c:=z[d+1].b++
  1028.  
  1029.  
  1030.   ARRAYs in objects are always rounded to even sizes, and put on
  1031.   even offsets:
  1032.  
  1033.   OBJECT mystring
  1034.     len:CHAR, data[9]:ARRAY
  1035.   ENDOBJECT
  1036.  
  1037.   SIZEOF mystring is 12, and "data" starts at offset 2.
  1038.  
  1039.   NOTE: OBJECTs in E are not like you might be used to in other
  1040.   languages, for example, not just any type can form a member of
  1041.   an object, and because of that, recursive object accesses like x.y.z
  1042.   don't make much sense (yet).
  1043.  
  1044. 8G. initialisation
  1045. ------------------
  1046.  
  1047. 1. Always initialised to NIL (or else, if explicitly stated)
  1048.    - global variables
  1049.      NOTE: for documentation purposes, it's always nicer if you
  1050.      write =NIL in the definitions of variables that you expect to be NIL.
  1051. 2. Initialised to '' and [] resp.
  1052.    - global and local STRINGs
  1053.    - global and local LISTs
  1054. 3. Not initialised
  1055.    - local variables (unless explicitly stated)
  1056.    - global and local ARRAYs
  1057.    - global and local OBJECTs
  1058.  
  1059.  
  1060.  
  1061. +---------------------------------------------------------------+
  1062. |                     9. BUILT-IN FUNCTIONS            |
  1063. +---------------------------------------------------------------+
  1064.  
  1065. 9A. io functions
  1066. ----------------
  1067.  
  1068.     WriteF(formatstring,args,...)
  1069.  
  1070. prints a string (which may contain formatting codes) to stdout. Zero
  1071. to unlimited arguments may be added. Note that, as formatstrings may
  1072. be created dynamically, no check on the correct number of arguments
  1073. is (can be) made. Examples:
  1074.  
  1075. WriteF('Hello, World!\n')    /* just write a lf terminated string */
  1076.  
  1077. WriteF('a = \d \n',a)        /* writes: "a = 123", if a was 123 */
  1078.  
  1079. See the bit about strings elsewhere for more.
  1080. NOTE: if stdout=NIL, for example if your program was started from the
  1081. Workbench, WriteF() will create an output window, and put the handle
  1082. in conout and stdout. This window will automatically be closed on
  1083. exit of the program, after the user typed a <return>. WriteF() is the
  1084. only function that will open this window, so if you want to do IO
  1085. on stdout, and want to be sure stdout<>NIL, perform a "WriteF('')"
  1086. as first instruction of your program to ensure output. If you want
  1087. to open a console window yourself, you may do so by placing the resulting
  1088. file handle in the 'stdout' and 'conout' variables, as your window will
  1089. then be closed automatically upon exit. If you wish to close this window
  1090. manually, make sure to set 'conout' back to NIL, to signal E that there's
  1091. no console window to be closed.
  1092.  
  1093.     Out(filehandle,char)      and      char:=Inp(filehandle)
  1094.  
  1095. Either write or read one single byte to some file or stdout
  1096. if char=-1 then an EOF was reached, or an error occurred.
  1097.  
  1098.     len:=FileLength(namestring)
  1099.  
  1100. lets you determine the length of a file you *may* wish to load, and
  1101. also, if it exists (returns -1 upon error/file not found).
  1102.  
  1103.     ok:=ReadStr(filehandle,estring)
  1104.  
  1105. see: string support
  1106.  
  1107.     oldout:=SetStdOut(newstdout)
  1108.  
  1109. Sets the standard output variable 'stdout'. Equivalent for:
  1110. oldout:=stdout; stdout:=newstdout
  1111.  
  1112.  
  1113.  
  1114. 9B. strings and string functions
  1115. --------------------------------
  1116.  
  1117. E has a datatype STRING. This is a string, from now on called 'Estring',
  1118. that may be modified and changed in size, as opposed to normal 'strings',
  1119. which will be used here for any zero-terminated sequence. Estrings are
  1120. downward compatible with strings, but not the other way around, so if an
  1121. argument requests a normal string, it can be either of them. If an Estring
  1122. is requested, don't use normal strings. Example of usage:
  1123.  
  1124. DEF s[80]:STRING, n                /* s is an estring with a maxlen of 80 */
  1125. ReadStr(stdout,s)                  /* read input from the console */
  1126. n:=Val(s,NIL)                      /* get a number out of it */
  1127.   ... etc.
  1128.  
  1129. Note that all string functions will handle cases where string tends to
  1130. get longer than the maximum length correctly;
  1131.  
  1132. DEF s[5]:STRING
  1133. StrAdd(s,'this string is longer than 5 characters',ALL)
  1134.  
  1135. s will contain just 'this '.
  1136. A string may also be allocated dynamically from system memory
  1137. with the function String(), (note: the pointer returned from this function
  1138. must always be checked against NIL)
  1139.  
  1140.     s:=String(maxlen)
  1141.  
  1142. DEF s[80]:STRING     is equivalent with     DEF s     and     s:=String(10)
  1143.  
  1144.  
  1145.     bool:=StrCmp(string,string,len)
  1146.  
  1147. compares two strings. len must be the number of bytes to compare,
  1148. or 'ALL' if the full length is to be compared. Returns TRUE or FALSE
  1149.  
  1150.     StrCopy(estring,string,len)
  1151.  
  1152. copies the string into the estring. If len=ALL, all will be copied.
  1153.  
  1154.     StrAdd(estring,string,len)
  1155.  
  1156. same as StrCopy(), only now the string is concatenated to the end.
  1157.  
  1158.     len:=StrLen(string)
  1159.  
  1160. calculates the length of any zero-terminated string
  1161.  
  1162.     len:=EstrLen(estring)
  1163.  
  1164. returns the length of an estring
  1165.  
  1166.     max:=StrMax(estring)
  1167.  
  1168. returns the maximum length of a estring
  1169.  
  1170.     RightStr(estring,estring,n)
  1171.  
  1172. fills estring with the last n characters of the second estring
  1173.  
  1174.     MidStr(estring,string,pos,len)
  1175.  
  1176. copies any number of characters (including all if len=ALL) from
  1177. position pos in string to estring
  1178. NOTEZ BIEN: in all string related functions where a position in a
  1179. string is used, the first character in a string has position 0,
  1180. not 1, as is common in languages like BASIC.
  1181.  
  1182.     value:=Val(string,read)
  1183.  
  1184. finds an integer encoded in ascii out of a string. Leading spaces/tabs
  1185. etc. will be skipped, and also hexadecimal numbers (1234567890ABCDEFabcdef)
  1186. and binary numbers (01) may be read this way if they are preceded by a
  1187. "$" or a "%" sign respectively. A minus "-" may indicate a negative integer.
  1188. Val() returns the number of characters read in the second argument, which
  1189. must be given by reference (<-!!!). If "read" returns 0 (value will be 0 too)
  1190. then the string did not contain an integer, or the value was too sizy
  1191. to fit in 32bit. "read" may be NIL.
  1192.  
  1193. examples of strings that would be parsed correctly:
  1194. '-12345', '%10101010', '   -$ABcd12'
  1195.  
  1196. these would return both as "value" and in var {read} a 0:
  1197. '', 'hello!'
  1198.  
  1199.  
  1200.     foundpos:=InStr(string1,string2,startpos)
  1201.  
  1202. searches string1 for the occurrence of string2, possibly starting from
  1203. another position than 0. Returned is the *address* at which the substring
  1204. was found, else -1.
  1205.  
  1206.     newstringadr:=TrimStr(string)
  1207.  
  1208. returns the *address* of the first character in a string, i.e., after
  1209. leading spaces, tabs etc.
  1210.  
  1211.     UpperStr(string)     and      LowerStr(string)
  1212.  
  1213. changes the case of a string.
  1214. TAKE NOTE: these functions modify the contents of 'string', so they may
  1215. only be used on estrings, and strings that are part of your programs data.
  1216. Effectively this means that if you obtain the address of a string through
  1217. some amiga-system function, you must first StrCopy() it to a string of
  1218. your program, then use these functions.
  1219.  
  1220.     ok:=ReadStr(filehandle,estring)
  1221.  
  1222. will read a string (ending in ascii 10) from any file or stdout.
  1223. ok contains -1 if an error occurred, or an EOF was reached.
  1224. Note: the contents of the string read so far is still valid.
  1225.  
  1226.     SetStr(estring,newlen)
  1227.  
  1228. manually sets the length of a string. This is only handy when you read
  1229. data into the estring by a function other then an E string function,
  1230. and want to continue using it as an Estring. For example, after
  1231. using a function that just puts a zero-terminated string at the
  1232. address of estring, use   SetStr(mystr,StrLen(mystr))  to make
  1233. it manipulatable again
  1234.  
  1235. for string linking functions see chapter 9H
  1236.  
  1237.  
  1238. 9C. lists and list functions
  1239. ----------------------------
  1240.  
  1241. Lists are like strings, only they consist of LONGs, not CHARs.
  1242. They may also be allocated either global, local or dynamic:
  1243.  
  1244. DEF mylist[100]:LIST         /* local or global */
  1245. DEF a
  1246. a:=List(10)                  /* dynamic */
  1247.  
  1248. (note that in the latter case, pointer 'a' may contain NIL)
  1249. Just as strings may be represented as constants in expressions, lists
  1250. have their constant equivalent:
  1251.  
  1252. [1,2,3,4]
  1253.  
  1254. The value of such an expression is a pointer to a ready initialised list.
  1255. Special feature is that they may have dynamic parts, i.e, which will
  1256. be filled in at runtime:
  1257.  
  1258. a:=3
  1259. [1,2,a,4]
  1260.  
  1261. moreover, lists may have some other type than the default LONG, like:
  1262.  
  1263. [1,2,3]:INT
  1264. [65,66,67,0]:CHAR                    /* equivalent with   'ABC'   */
  1265. ['topaz.font',8,0,0]:textattr
  1266. OpenScreenTagList(NIL,[SA_TITLE,'MyScreen',TAG_DONE])
  1267.  
  1268. As shown in the latter examples, lists are extremely useful with
  1269. system functions: they are downward compatible with an ARRAY OF LONG,
  1270. and object-typed ones can be used wherever a system function needs
  1271. a pointer to some structure, or an array of those.
  1272. Taglists and vararg functions may also be used this way.
  1273. NOTEZ BIEN: all list functions only work with LONG lists, typed-lists
  1274. are only convenient in building complex data structures and expressions.
  1275.  
  1276. As with strings, a certain hierarchy holds:
  1277. list variables -> constant lists -> array of long/ptr to long
  1278. When a function needs an array of long you might just as well give a list
  1279. as argument, but when a function needs a listvar, or a constant list,
  1280. then an array of long won't do.
  1281.  
  1282. It's important that one understands the power of lists and in particular
  1283. typed-lists: these can save you lots of trouble when building just
  1284. about any data-structure. Try to use these lists in your own programs,
  1285. and see what function they have in the example-programs. once you get
  1286. to grips with lists, you'll never want to write a program without them.
  1287.  
  1288. summary:
  1289.  
  1290. [<item>,<item>,... ]        immediate list (of LONGs, use with listfuncs)
  1291. [<item>,<item>,... ]:<type>    typed list (just to build data structures)
  1292.  
  1293. If <type> is a simple type like INT or CHAR, you'll just have the
  1294. initialised equivalent of ARRAY OF <type>, if <type> is an object-name,
  1295. you'll be building initialised objects, or ARRAY OF <object>, depending
  1296. on the length of the list.
  1297.  
  1298. If you write    [1,2,3]:INT   you'll create a data structure of 6 bytes,
  1299. of 3 16bit values to be precise. The value of this expression then
  1300. is a pointer to that memory area. Same works if, for example, you have
  1301. an object like:
  1302.  
  1303. OBJECT myobject
  1304.   a:LONG, b:CHAR, c:INT
  1305. ENDOBJECT
  1306.  
  1307. writing    [1,2,3]:myobject     would then mean creating a data structure
  1308. in memory of 8 bytes, with the first four bytes being a LONG with value 1,
  1309. the following byte a CHAR with value 2, then a pad byte, and the last
  1310. two bytes an INT (2 bytes) with value 3. you could also write:
  1311.  
  1312. [1,2,3,4,5,6,7,8,9]:myobject
  1313.  
  1314. you would be creating an ARRAY OF myobject with size 3. Note that such
  1315. lists don't have to be complete (3,6,9 and so on elements), you may
  1316. create partial objects with lists of any size
  1317.  
  1318. One last note on data size: on the amiga, you may rely on the fact that
  1319. a structure like 'myobject' has size 8, and that it has a pad byte
  1320. to have word (16bit) alignment. It is however very likely that an
  1321. E-compiler for 80x86 architectures will not use the pad byte and make
  1322. it a 7byte structure, and that an E-compiler for a sun-sparc architecture
  1323. (if I'm not mistaken) will try to align on 32bit boundaries, thus make
  1324. it a 10 or 12 byte structure. Some microprocessors (they are rare, but
  1325. they exist) even use (36:18:9) as numbers of bits for their types
  1326. (LONG:INT:CHAR), instead of (32:16:8) as we're used to. So don't make too
  1327. great an assumption on the structure of OBJECTs and LISTs if you want to
  1328. write code that stands a chance of being portable or doesn't rely on side
  1329. effects.
  1330.  
  1331.  
  1332.     ListCopy(listvar,list,num)
  1333.  
  1334. Copies num elements from list to listvar. example:
  1335. DEF mylist[10]:LIST
  1336. ListCopy(mylist,[1,2,3,4,5],ALL)
  1337.  
  1338.     ListAdd(listvar,list,num)
  1339.  
  1340. Copies num items of list to the tail of listvar.
  1341.  
  1342.     ListCmp(list,list,num)
  1343.  
  1344. Compares two lists, or some part of them.
  1345.  
  1346.     len:=ListLen(list)
  1347.  
  1348. Returns length of list, like     ListLen([a,b,c])    would return 3
  1349.  
  1350.     max:=ListMax(listvar)
  1351.  
  1352. returns maximum possible length of a listvar.
  1353.  
  1354.     value:=ListItem(list,index)
  1355.  
  1356. functions as    value:=list[index]    with the difference that
  1357. list may also be a constant value instead of a pointer. This is
  1358. very usefull in situations like this where we directly want to
  1359. use a list of values:
  1360.  
  1361. WriteF(ListItem(['ok!','no mem!','no file!'],error))
  1362.  
  1363. this prints an errormessage according to "error". it's similar to:
  1364.  
  1365. DEF dummy:PTR TO LONG
  1366. dummy:=['ok!','no mem!','no file!']
  1367. WriteF(dummy[error])
  1368.  
  1369.     SetList(listvar,newlen)
  1370.  
  1371. manually sets the length of a list. This will only be useful when you read
  1372. data into the list by a function other then a list-specific function,
  1373. and want to continue using it as a true list.
  1374.  
  1375. for list functions that make use of quoted expressions see chapter 11C.
  1376. for list linking functions see chapter 9H.
  1377.  
  1378.  
  1379. 9D. intuition support functions
  1380. -------------------------------
  1381.  
  1382.     wptr:=OpenW(x,y,width,height,IDCMP,wflags,title,screen,sflags,gadgets)
  1383.  
  1384. creates a window where wflags are flags for window layout
  1385. (like BACKDROP, SIMPLEREFRESH e.d, usually $F) and sflags are
  1386. for specifying the type of screen to open on (1=wb,15=custom).
  1387. screen must only be valid if sflags=15, else NIL will do.
  1388. gadgets may point to a glist structure, which you can easily
  1389. create with the Gadget() function, else NIL.
  1390.  
  1391.     CloseW(wptr)
  1392.  
  1393. closes that screen again. Only difference from CloseWindow()
  1394. is that it accepts NIL-pointers and sets stdrast back to NIL.
  1395.  
  1396.     sptr:=OpenS(width,height,depth,sflags,title)
  1397.  
  1398. opens a custom screen for you. depth is number of bitplanes (1-6, 1-8 AGA),
  1399. sflags is something like 0, or $8000 for hires (add 4 for interlace).
  1400.  
  1401.     CloseS(sptr)
  1402.  
  1403. as CloseW(), now for screens.
  1404.  
  1405.     nextbuffer:=Gadget(buffer,glist,id,flags,x,y,width,string)
  1406.  
  1407. This function creates a list of gadgets, which can then be put in your
  1408. window by giving them as an argument to OpenW(), or afterwards with
  1409. intuition functions like AddGlist().
  1410. buffer is mostly an ARRAY of at least GADGETSIZE bytes to hold all the
  1411. structures associated with one gadget, id is any number that may help you
  1412. remember which gadget was pressed when an IntuiMessage arrives.
  1413. Flags are: 0=normal gadget, 1=boolean gadget, 3=boolean gadget that is
  1414. selected. Width is width in pixels, that should be large enough to hold
  1415. the string, which will be auto-centered. glist should be NIL for the first
  1416. gadget, and glistvar for all others, so E may link all gadgets.
  1417. The function returns a pointer to the next buffer (=buffer+GADGETSIZE).
  1418. Example for three gadgets:
  1419.  
  1420. CONST MAXGADGETS=GADGETSIZE*3
  1421.  
  1422. DEF buf[MAXGADGETS]:ARRAY, next, wptr
  1423.  
  1424. next:=Gadget(buf,NIL,1,0,10,20,80,'bla')   /* the 1st gadget */
  1425. next:=Gadget(next,buf,... )
  1426. next:=Gadget(next,buf,... )                /* any amount linked 2 1st */
  1427.  
  1428. wptr:=OpenW( ...,buf)
  1429.  
  1430. See examples like SuperVisor.e for a real-life example.
  1431.  
  1432.  
  1433.     code:=Mouse()
  1434.  
  1435. gives you the current state of all 2 or 3 mouse buttons; left=1,
  1436. right=2 and middle=4. If for example code=3 then left and right were
  1437. pressed together.
  1438. NOTEZ BIEN: this is not a real intuition function, if you want to
  1439. know about mouse-events the proper way, you'll have to check the
  1440. intuimessages that your window receives. This is the only E
  1441. function that directly checks the hardware, and thus only usefull
  1442. in demo-like programs.
  1443.  
  1444.     x:=MouseX(win)      and     y:=MouseY(win)
  1445.  
  1446. enables you to read the mouse coordinates. win is the window
  1447. they need to be relative to.
  1448.  
  1449.     class:=WaitIMessage(window)
  1450.  
  1451. This function makes it easier to just wait for a window event. It simply
  1452. waits until a intuimessage arrives, and returns the class of the event.
  1453. It stores other variables like code and qualifiers as private global
  1454. variables, for access with functions described below.
  1455. WaitIMessage() represents the following code:
  1456.  
  1457. PROC waitimessage(win:PTR TO window)
  1458.   DEF port,mes:PTR TO intuimessage,class,code,qual,iaddr
  1459.   port:=win.userport
  1460.   IF (mes:=GetMsg(port))=NIL
  1461.     REPEAT
  1462.       WaitPort(port)
  1463.     UNTIL (mes:=GetMsg(port))<>NIL
  1464.   ENDIF
  1465.   class:=mes.class
  1466.   code:=mes.code             /* stored internally */
  1467.   qual:=mes.qualifier
  1468.   iaddr:=mes.iaddress
  1469.   ReplyMsg(mes)
  1470. ENDPROC class
  1471.  
  1472. as you see, it gets exactly one message, and does not forget about
  1473. multiple messages arriving in one event, if called more than once.
  1474. For example, say you opened a window that displays something and just
  1475. waits for a closegadget (you specified IDCMP_CLOSEWINDOW only):
  1476.  
  1477. WaitIMessage(mywindow)
  1478.  
  1479. or, you have a program that waits for more types of events, handles
  1480. them in a loop, and ends on a closewindow event:
  1481.  
  1482. WHILE (class:=WaitIMessage(win))<>IDCMP_CLOSEWINDOW
  1483.   /* handle other classes */
  1484. ENDWHILE
  1485.  
  1486.     code:=MsgCode()    qual:=MsgQualifier()    iaddr:=MsgIaddr()
  1487.  
  1488. These all supply you with the private global variables as mentioned
  1489. before. the values returned are all defined by the most recent call
  1490. to WaitIMessage(). Example:
  1491.  
  1492. IF class:=IDCMP_GADGETUP
  1493.   mygadget:=MsgIaddr()
  1494.   IF mygadget.userdata=1 THEN  /* ... user pressed gadget #1 */
  1495. ENDIF
  1496.  
  1497.  
  1498.  
  1499. 9E. graphics support functions
  1500. ------------------------------
  1501.  
  1502. All graphics support functions that do not explicitly ask for a rastport,
  1503. make use of the system-variable 'stdrast'. It is automatically defined by
  1504. the last call to OpenW() or OpenS(), and is set to NIL by CloseW() and
  1505. CloseS(). Calling these routines while stdrast is still NIL is legal.
  1506. stdrast may be manually set by SetStdRast() or stdrast:=myrast
  1507.  
  1508.     Plot(x,y,colour)
  1509.  
  1510. Draws a single dot on your screen/window in one of the colours available.
  1511. colour ranges from 0-255, or 0-31 on pre-AGA machines.
  1512.  
  1513.     Line(x1,y1,x2,y2,colour)
  1514.  
  1515. Draws a line
  1516.  
  1517.     Box(x1,y1,x2,y2,colour)
  1518.  
  1519. Draws a box
  1520.  
  1521.     Colour(foreground,background)
  1522.  
  1523. sets the colours for all graphics functions (from the library) that
  1524. do not take a colour as argument. This is the colour *register*
  1525. (i.e 0-31) and not colour *value*
  1526. NOTE: functions that have "colour" as an argument, change the Apen
  1527. of stdrast.
  1528.  
  1529.     TextF(x,y,formatstring,args,...)
  1530.  
  1531. exactly the same function as WriteF(), only outputs to some (x,y) on
  1532. your stdrast, instead of stdout. See: WriteF() and strings in the language
  1533. reference.
  1534.  
  1535.     oldrast:=SetStdRast(newrast)
  1536.  
  1537. changes the output rastport of the e graphics functions
  1538.  
  1539.     SetTopaz(size)
  1540.  
  1541. lets you set the font of the rastport "stdrast" to topaz, just to be sure
  1542. that some custom system font of the user won't skrew up your window layout.
  1543. size is of course 8 or 9
  1544.  
  1545.  
  1546. 9F. system support functions
  1547. ----------------------------
  1548.  
  1549.     bool:=KickVersion(vers)
  1550.  
  1551. Will give TRUE if the kickstart in the machine your program is running
  1552. on is equal or higher than vers, else FALSE
  1553.  
  1554.     mem:=New(n)
  1555.  
  1556. This dynamically creates an array (or memory area, if you wish) of
  1557. n bytes. Difference with AllocMem() is that it is called automatically
  1558. with flags $10000 (i.e cleared mem, any type) and that no calls to
  1559. Dispose() are necessary, as it is linked to a memory list that is
  1560. automatically de-allocated upon exit of your program.
  1561.  
  1562.     Dispose(mem)
  1563.  
  1564. Frees any mem allocated by New(). You only have to use this function
  1565. if you explicitly wish to free memory _during_ your program, as all
  1566. is freed at the end anyway.
  1567.  
  1568.     CleanUp(returnvalue)
  1569.  
  1570. Exits the program from any point. It is the replacement for the DOS
  1571. call Exit(): never use that one! instead use CleanUp(), which allows
  1572. for the deallocation of memory, closing libraries correctly etc.
  1573. The return value will be given to dos as returncode.
  1574.  
  1575.     amount:=FreeStack()
  1576.  
  1577. returns the amount of free stack space left. This should always be 1000 or
  1578. more. See the chapter 'implementation issues' on how E organizes its
  1579. stack. If you don't do heavy recursion, you need not worry about your free
  1580. stack space.
  1581.  
  1582.     bool:=CtrlC()
  1583.  
  1584. Returns TRUE if Ctrl-C was pressed since you last checked, else FALSE.
  1585. This only works for programs running on a console, i.e. cli-programs.
  1586.  
  1587. Example of how these last three functions may be used:
  1588.  
  1589. /* calculate faculty from command-line argument */
  1590.  
  1591. OPT STACK=100000
  1592.  
  1593. PROC main()
  1594.   DEF num,r
  1595.   num:=Val(arg,{r})
  1596.   IF r=0 THEN WriteF('bad args.\n') ELSE WriteF('result: \d\n',fac(num))
  1597. ENDPROC
  1598.  
  1599. PROC fac(n)
  1600.   DEF r
  1601.   IF FreeStack()<1000 OR CtrlC() THEN CleanUp(5)    /* xtra check */
  1602.   IF n=1 THEN r:=1 ELSE r:=fac(n-1)*n
  1603. ENDPROC r
  1604.  
  1605. Of course, this recursion will hardly run out of stack space, and when it
  1606. does, it's halted by FreeStack() so fast you won't have time to press
  1607. CtrlC, but it's the idea that counts here.
  1608. A definition of fac(n) like:
  1609.  
  1610. PROC fac(n) RETURN IF n=1 THEN 1 ELSE fac(n-1)*n
  1611.  
  1612. would be less safe.
  1613.  
  1614.  
  1615. 9G. math and other functions
  1616. -------------------
  1617.  
  1618.     a:=And(b,c)           a:=Or(b,c)           a:=Not(b)
  1619.     a:=Eor(b,c)
  1620.  
  1621. These work with the usual operations, boolean as well as arithmetic.
  1622. Note that for And() and Or() an operator exists.
  1623.  
  1624.     a:=Mul(b,c)           a:=Div(a,b)
  1625.  
  1626. Performs the same operation as the '*' and '/' operators, but now in
  1627. full 32bit. For speed reasons, normal operations are 16bit*16bit=32bit
  1628. and 32bit/16bit=16bit. This is sufficient for nearly all calculations,
  1629. and where it's not, you may use Mul() and Div(). NOTE: in the Div
  1630. case, a is divided by b, not b by a.
  1631.  
  1632.         bool:=Odd(x)          bool:=Even(x)
  1633.  
  1634. Return TRUE or FALSE if some expression is Odd or Even
  1635.  
  1636.     randnum:=Rnd(max)    seed:=RndQ(seed)
  1637.  
  1638. Rnd() computes a random number from an internal seed in range 0 .. max-1.
  1639. For example,  Rnd(1000)   returns integer from 0..999
  1640. To initialise the internal seed, call Rnd() with a negative value;
  1641. the Abs() of that value will be the initial seed.
  1642.  
  1643. RndQ() computes a random number "Q"uicker than Rnd() does, but returns
  1644. only full range 32bit random numbers. Use the result as the seed for
  1645. the next call, and for startseed, use any large value, like $A6F87EC1
  1646.  
  1647.     absvalue:=Abs(value)
  1648.  
  1649. computes the absolute value.
  1650.  
  1651.     a:=Mod(b,c)
  1652.  
  1653. Divides 32bit b by 16bit c and returns 16bit modulo a
  1654.  
  1655.     x:=Shl(y,num)         x:=Shr(y,num)
  1656.  
  1657. shifts y num bits to left or right.
  1658.  
  1659.     a:=Long(adr)          a:=Int(adr)          a:=Char(adr)
  1660.  
  1661. peeks into memory at some address, and returns the value found. This
  1662. works with 32, 16 and 8 bit values respectively. Note that the compiler does
  1663. not check if 'adr' is valid. These functions are available in E for
  1664. those cases where reading and writing in memory with PTR TO <type>
  1665. would only make a program more complex or less efficient. You are not
  1666. encouraged to use these functions.
  1667.  
  1668.     PutLong(adr,a) and    PutInt(adr,a)        PutChar(adr,a)
  1669.  
  1670. Pokes value 'a' into memory. See: Long()
  1671.  
  1672.  
  1673. 9H. string and list linking functions
  1674. -------------------------------------
  1675. E provides for a set of functions that allows the creation of
  1676. linked list with the STRING and LIST datatype, or strings and lists
  1677. that were created with String() and List() respectively. As you may
  1678. know by now, strings and lists, complex datatypes, are pointers
  1679. to their respective data, and have extra fields to a negative offset
  1680. of that pointer specifying their current length and maxlength. the
  1681. offsets of these fields are PRIVATE. as an addition to those two,
  1682. any complex datatype has a 'next' field, which is set to NIL by
  1683. default, which may be used to build linked list of strings, for example.
  1684. in the following, I will use 'complex' to denote a ptr to a STRING
  1685. or LIST, and 'tail' to denote another such pointer, or one that already
  1686. has other strings linked to it. 'tail' may also be a NIL pointer,
  1687. denoting the end of a linked list.
  1688. The following functions may be used:
  1689.  
  1690.     complex:=Link(complex,tail)
  1691.  
  1692. puts the value tail into the 'next' field of complex. returns again complex.
  1693. example:
  1694.  
  1695. DEF s[10]:STRING, t[10]:STRING
  1696. Link(s,t)
  1697.  
  1698. creates a linked list like:    s --> t --> NIL
  1699.  
  1700.     tail:=Next(complex)
  1701.  
  1702. reads the 'next' field of var complex. this may of course be NIL, or
  1703. a complete linked list. Calling Next(NIL) will result in NIL, so it's
  1704. safe to call Next when you're not sure if you're at the end of a linked list.
  1705.  
  1706.     tail:=Forward(complex,num)
  1707.  
  1708. same as Next(), only goes forward num links, instead of one, thus:
  1709.  
  1710. Next(c) = Forward(c,1)
  1711.  
  1712. You may safely call Forward() with a num that is way too large;
  1713. Forward will stop if it encounters NIL while searching links, and
  1714. will return NIL.
  1715.  
  1716.     DisposeLink(complex)
  1717.  
  1718. same as Dispose(), with two differences: it's only for strings and
  1719. lists allocated with String() or List(), and will automatically
  1720. de-allocate the tail of complex too. Note that large linked lists
  1721. containing strings allocated with String() as well as some allocated
  1722. locally or globally with STRING may also be de-allocated this way.
  1723.  
  1724. For a good example of how linked lists of strings may be put to
  1725. good use in real-life programs, see 'D.e'
  1726.  
  1727.  
  1728.  
  1729. +---------------------------------------------------------------+
  1730. |               10. LIBRARY FUNCTIONS AND MODULES        |
  1731. +---------------------------------------------------------------+
  1732.  
  1733. 10A. built-in library calls
  1734. --------------------------
  1735. As you may have noticed from previous sections, the piece of code
  1736. automatically linked to the start of your code, called the "initialisation code",
  1737. always opens the four libraries Intuition, Dos, Graphics and Mathffp,
  1738. and because of this, the compiler has all the calls to those five libraries
  1739. (including Exec) integrated in the compiler (there are a few hundred of them).
  1740. These are up to AmigaDos v2.04, v3.00 should be included by the next version
  1741. of Amiga E. To call Open() from the dos library, simply say:
  1742.  
  1743. handle:=Open('myfile',OLDFILE)
  1744.  
  1745. or AddDisplayInfo() from the graphics library:
  1746.  
  1747. AddDisplayInfo(mydispinfo)
  1748.  
  1749. it's as simple as that.
  1750.  
  1751.  
  1752. 10B. interfacing to the amiga system with the 2.04 modules
  1753. ----------------------------------------------------------
  1754. To use any other library than the five in the previous section, you'll
  1755. need to resort to modules. Also, if you wish to use some OBJECT or CONST
  1756. definition from the Amiga includes as is usual in C or assembler,
  1757. you'll need modules. Modules are binary files which may include constant,
  1758. object, library and function (code) definitions. The fact that they're
  1759. binary has the advantage over ascii (as in C and assembly), that they
  1760. need not be compiled over and over again, each time your program is
  1761. compiled. The disadvantage is that they cannot be simply be viewed; they
  1762. need a utility like ShowModule (see utility.doc) to make their contents
  1763. visible. The modules that contain the library definitions (i.e the calls)
  1764. are in the root of emodules: (the modules dir in the distribution), the
  1765. constant/object definitions are in the subdirectories, structured just
  1766. like the originals from Commodore.
  1767.  
  1768. MODULE
  1769.  
  1770. syntax:        MODULE <modulenames>,...
  1771. Loads a module. A module is a binary file containing information on libraries,
  1772. constants, and sometimes functions. Using modules enables you to use
  1773. libraries and functions previously unknown to the compiler.
  1774.  
  1775. Now for an example, below is a short version of the source/examples/asldemo.e
  1776. source that uses modules to put up a filerequester from the 2.0 Asl.library.
  1777.  
  1778.  
  1779. MODULE 'Asl', 'libraries/Asl'
  1780.  
  1781. PROC main()
  1782.   DEF req:PTR TO filerequestr
  1783.   IF aslbase:=OpenLibrary('asl.library',37)
  1784.     IF req:=AllocFileRequest()
  1785.       IF RequestFile(req) THEN WriteF('File: "\s" in "\s"\n',req.file,req.dir)
  1786.       FreeFileRequest(req)
  1787.     ENDIF
  1788.     CloseLibrary(aslbase)
  1789.   ENDIF
  1790. ENDPROC
  1791.  
  1792.  
  1793. From the modules 'asl', the compiler takes asl-function definitions like
  1794. RequestFile(), and the global variable 'aslbase', which only needs to
  1795. be initialised by the programmer. From 'libraries/Asl', it takes
  1796. the definition of the filerequestr object, which we use to read the
  1797. file the user picked. Well, that wasn't all that hard: did you think
  1798. it was that easy to program a filerequester in E?
  1799.  
  1800.  
  1801. +---------------------------------------------------------------+
  1802. |                    11. QUOTED EXPRESSIONS            |
  1803. +---------------------------------------------------------------+
  1804.  
  1805. 11A. quoting and scope
  1806. ----------------------
  1807. Quoted expressions start with a backquote. The value of a quoted
  1808. expression is not the result from the computation of the expression,
  1809. but the address of the code. This result may then be passed on as
  1810. a normal variable, or as an argument to certain functions.
  1811. example:
  1812.  
  1813. myfunc:=`x*x*x
  1814.  
  1815. myfunc is now a pointer to a function that computes x3 when evaluated.
  1816. These pointers to functions are very different from normal PROCs, and
  1817. you should never mix the two up. The biggest differences are that a
  1818. quoted expression is just a simple expression, and thus cannot have its
  1819. own local variables. In our example, "x" is just a local or global variable.
  1820. That's where we have to be cautious:
  1821. if we evaluate myfunc somewhat later in the same PROC, x may be local,
  1822. but if myfunc is given as parameter to another PROC, and then evaluated,
  1823. x needs of course to be global. There's no scope checking on this.
  1824.  
  1825. 11B. Eval()
  1826. -----------
  1827.     Eval(func)
  1828.  
  1829. simply evaluates a quoted expression (exp = Eval(`exp)).
  1830.  
  1831. NOTE: because E is a somewhat typeless language, accidentally writing
  1832. "Eval(x*x)"  instead of  "Eval(`x*x)"  will go unnoticed by the
  1833. compiler, and will give you big runtime problems: the value of x*x
  1834. will be used as a pointer to code.
  1835.  
  1836. To understand why 'quoted expressions' is a powerful feature think of the
  1837. following cases: if you were to perform a set of actions on a set of different
  1838. variables, you'd normally write a function, and call that function with
  1839. different arguments. But what happens when the element that you want to give
  1840. as argument is a piece of code? in traditional languages this would not be
  1841. possible, so you would have to 'copy' the blocks of code representing your
  1842. function, and put the expression in it. Not in E. say you wanted to write
  1843. a program that times the execution time of different expressions. In E you
  1844. would simply write:
  1845.  
  1846. PROC timing(func,title)
  1847.   /* do all sorts of things to initialise time */
  1848.   Eval(func)
  1849.   /* and the rest */
  1850.   WriteF('time measured for \s was \d\n',title,t)
  1851. ENDPROC
  1852.  
  1853. and then call it with:
  1854.  
  1855. timing(`x*x*x,'multiplication')
  1856. timing(`sizycalc(),'large calculation')
  1857.  
  1858.  
  1859. in any other imperative language, you would have to write out
  1860. copies of timing() for every call to it, or you would have to
  1861. put each expression in a separate function. This is just a simple
  1862. example: think about what you could do with data structures (LISTs)
  1863. filled with unevaluated code:
  1864.  
  1865. drawfuncs:=[`Plot(x,y,c),`Line(x,y,x+10,y+10,c),`Box(x,y,x+20,y+20,c)]
  1866.  
  1867. Note that this idea of functions as normal variables/values is not new
  1868. in E, quoted expressions are literally from LISP, which also has the
  1869. somewhat more powerful so-called Lambda function, which can also be
  1870. given as argument to functions; E's quoted expressions can also be
  1871. seen as parameterless (or global parameter only) lambda's.
  1872.  
  1873.  
  1874. 11C. built-in functions
  1875. ----------------------
  1876.     MapList(varadr,list,listvar,func)
  1877.  
  1878. performs some function on all elements of list and returns all
  1879. results in listvar. func must be a quoted expression (see above),
  1880. and var (which ranges over the list) must be given by reference. Example:
  1881.  
  1882. MapList({x},[1,2,3,4,5],r,`x*x)       results r in:     [1,4,9,16,25]
  1883.  
  1884.     ForAll(varadr,list,func)
  1885.  
  1886. Returns TRUE if for all elements in the list the function (quoted
  1887. expression) evaluates to TRUE, else FALSE. May also be used to perform
  1888. a certain function for all elements of a list:
  1889.  
  1890. ForAll({x},['one','two','three'],`WriteF('example: \s\n',x))
  1891.  
  1892.     Exists(varadr,list,func)
  1893.  
  1894. As ForAll(), only this one returns TRUE if for any element the function
  1895. evaluates to TRUE (<>0). note that ForAll() always evaluates all elements,
  1896. but Exists() possibly does not.
  1897.  
  1898. Example of how to use these functions in a practical fashion:
  1899. we allocate different sizes of memory in one statement, check them
  1900. all together at once, and free them all, but still only those that
  1901. succeeded. (example is v37+)
  1902.  
  1903.  
  1904. PROC main()
  1905.   LOCAL mem[4]:LIST,x
  1906.   MapList({x},[200,80,10,2500],mem,`AllocVec(x,0)) /* alloc some */
  1907.   IF ForAll({x},mem,`x)                            /* suxxes ? */
  1908.     WriteF('Yes!\n')
  1909.   ELSE
  1910.     WriteF('No!\n')
  1911.   ENDIF
  1912.   ForAll({x},mem,`IF x THEN FreeVec(x) ELSE NOP)   /* free only those <>NIL */
  1913. ENDPROC
  1914.  
  1915.  
  1916. Note the absence of iteration in this code. Just try to rewrite this
  1917. example in any other language to see why this is special.
  1918.  
  1919.  
  1920. +---------------------------------------------------------------+
  1921. |                  12. FLOATING POINT SUPPORT            |
  1922. +---------------------------------------------------------------+
  1923.  
  1924. 12A. using floats and float operator overloading
  1925. ------------------------------------------------
  1926. Overloading the standard operators + * etc with float equivalents is
  1927. possible starting from v2.0 of Amiga E, but I've removed the main
  1928. documentation on it because it is likely that the float-concept in E
  1929. will change as of v2.2 or later: that version may allow for 68881 inline
  1930. code generation next to normal FFP routines in a transparent fashion.
  1931.  
  1932. If you really want to use floats with v2.1b, you are advised to use the
  1933. SpXxx() built-in routines from the mathffp.library.
  1934. Example:
  1935.  
  1936. x:=SpMul(y,0.013483)
  1937.  
  1938. Be aware that when v2.5 comes out, your sources may need to be
  1939. changed (for the better!).
  1940.  
  1941. 12B. float expressions and conversion
  1942. -------------------------------------
  1943. as 12A.
  1944.  
  1945.  
  1946. +---------------------------------------------------------------+
  1947. |                      13. EXCEPTION HANDLING            |
  1948. +---------------------------------------------------------------+
  1949.  
  1950. 13A. defining exception handlers (HANDLE/EXCEPT)
  1951. ------------------------------------------------
  1952. The exception mechanism in E is basically the same as in ADA; it
  1953. provides for flexible reaction on errors in your program and
  1954. complex resource management. NOTE: the term 'exception' in E has
  1955. very little to do with exceptions caused directly by 680x0 processors.
  1956.  
  1957. An exception handler is a piece of program code that will be invoked
  1958. when runtime errors occur, such as windows that fail to open or
  1959. memory that is not available. You, or the runtime system itself,
  1960. may signal that something is wrong (this is called "raising an
  1961. exception"), and then the runtime-system will try and find the
  1962. appropriate exception handler. I say "appropriate" because a program
  1963. can have more than one exception handler, on all levels of a program.
  1964. A normal function definition may (as we all know) look like this:
  1965.  
  1966. PROC bla()
  1967.   /* ... */
  1968. ENDPROC
  1969.  
  1970. a function with an exception handler looks like this:
  1971.  
  1972. PROC bla() HANDLE
  1973.   /* ... */
  1974. EXCEPT
  1975.   /* ... */
  1976. ENDPROC
  1977.  
  1978. The block between PROC and EXCEPT is executed as normal, and if no
  1979. exception occur, the block between EXCEPT and ENDPROC is skipped, and
  1980. the procedure is left at ENDPROC. If an exception is raised, either
  1981. in the PROC part, or in any function that is called in this block,
  1982. an exception handler is invoked.
  1983.  
  1984. 13B. using the Raise() function
  1985. -------------------------------
  1986. There are many ways to actually "raise" an exception, the simplest
  1987. is through the function Raise():
  1988.  
  1989.     Raise(exceptionID)
  1990.  
  1991. the exception ID is simply a constant that defines the type of
  1992. exception, and is used by handlers to determine what went wrong.
  1993. Example:
  1994.  
  1995. ENUM NOMEM,NOFILE  /* and others */
  1996.  
  1997. PROC bla() HANDLE
  1998.   DEF mem
  1999.   IF (mem:=New(10))=NIL THEN Raise(NOMEM)
  2000.   myfunc()
  2001. EXCEPT
  2002.   SELECT exception
  2003.     CASE NOMEM
  2004.       WriteF('No memory!\n')
  2005.     /* ... and others */
  2006.   ENDSELECT
  2007. ENDPROC
  2008.  
  2009. PROC myfunc()
  2010.   DEF mem
  2011.   IF (mem:=New(10))=NIL THEN Raise(NOMEM)
  2012. ENDPROC
  2013.  
  2014. The "exception" variable in the handler always contains the value of
  2015. the argument to the Raise() call that invoked it.
  2016. In both New() cases, the Raise() function invokes the handler of
  2017. function bla(), and then exits it correctly to the caller of bla().
  2018. If myfunc() had its own exception-handler, that one would be invoked
  2019. for the New() call in myfunc(). The scope of a handler is from the start
  2020. of the PROC in which it is defined until the EXCEPT keyword, including
  2021. all calls made from there.
  2022.  
  2023. This has three consequences:
  2024. A. handlers are organised in a recursive fashion, and which handler is
  2025.    actually invoked is dependant on which function calls which at runtime;
  2026. B. if an exception is raised within a handler, the handler of a lower
  2027.    level is invoked. This characteristic of handlers may be used
  2028.    to implement complex recursive resource allocation schemes with
  2029.    great ease, as we'll see shortly.
  2030. C. If an exception is raised on a level where no lower-level handler
  2031.    is available (or in a program that hasn't got any handlers at all),
  2032.    the program is terminated. (i.e: Raise(x) has the same effect as
  2033.    CleanUp(0))
  2034.  
  2035.  
  2036. 13C. defining exceptions for built-in functions (RAISE/IF)
  2037. ---------------------------------------------------------
  2038. With exceptions like before, we have made a major gain over the
  2039. old way of defining our own "error()" function, but still it is
  2040. a lot of typing to have to check for NIL with every call to New().
  2041.  
  2042. The E exception handling system allows for definition of exceptions
  2043. for all E functions (like New(), OpenW() etc.), and for all Library
  2044. functions (OpenLibrary(), AllocMem() etc.), even for those
  2045. included by modules. Syntax:
  2046.  
  2047. RAISE <exceptionId> IF <func> <comp> <value> , ...
  2048.  
  2049. the part after RAISE may be repeated with a ",".
  2050. Example:
  2051.  
  2052. RAISE NOMEM IF New()=NIL,
  2053.       NOLIBRARY IF OpenLibrary()=NIL
  2054.  
  2055. the first line says something like: "whenever a call to New() results
  2056. in NIL, automatically raise the NOMEM exception".
  2057. <comp> may be any of = <> > < >= <=
  2058. After this definition, we may write all through our programs:
  2059.  
  2060. mem:=New(size)
  2061.  
  2062. without having to write:
  2063.  
  2064. IF mem=NIL THEN Raise(NOMEM)
  2065.  
  2066. Note that the only difference is that "mem" never gets any value
  2067. if the runtime system invokes the handler: code is generated for
  2068. every call to New() to check directly after New() returns and call
  2069. Raise() when necessary.
  2070.  
  2071. We'll now be implementing a small example that would be complex to solve
  2072. without exception handling: we call a function recursively, and in each
  2073. we allocate a resource (in this case memory), which we allocate before,
  2074. and release after the recursive call. What happens when somewhere high
  2075. in the recursion a severe error occurs, and we have to leave the program?
  2076. right: we would (in a conventional language) be unable to free all the
  2077. resources lower in the recursion while leaving the program, because all
  2078. pointers to those memory areas are stored in unreachable local variables.
  2079. In E, we can simply raise an exception, and from the end of the handler
  2080. again raise an exception, thus recursively calling all handlers and
  2081. releasing all resources. Example:
  2082.  
  2083.  
  2084. CONST SIZE=100000
  2085. ENUM NOMEM  /* ,... */
  2086.  
  2087. RAISE NOMEM IF AllocMem()=NIL
  2088.  
  2089. PROC main()
  2090.   alloc()
  2091. ENDPROC
  2092.  
  2093. PROC alloc() HANDLE
  2094.   DEF mem
  2095.   mem:=AllocMem(SIZE,0)        /* see how many blocks we can get */
  2096.   alloc()            /* do recursion */
  2097.   FreeMem(mem,SIZE)        /* we'll never get here */
  2098. EXCEPT
  2099.   IF mem THEN FreeMem(mem,SIZE)
  2100.   Raise(exception)        /* recursively call all handlers */
  2101. ENDPROC
  2102.  
  2103.  
  2104. This is of course a simulation of a natural programming problem that
  2105. is usually far more complex, and thus the need for exception handling
  2106. becomes far more obvious. For a real-life example program whose error
  2107. handling would have become very difficult without exception
  2108. handlers, see the 'D.e' utility source.
  2109.  
  2110. 13D. use of exception-ID's
  2111. --------------------------
  2112.  
  2113. In real life an exception-ID is ofcourse a normal 32-bit value,
  2114. and you may pass just about anything to an exception handler: for
  2115. example, some use it to pass error-description strings
  2116.  
  2117. Raise('Could not open "gadtools.library"!')
  2118.  
  2119. However, if you want to use exceptions in expandabele fashion and you
  2120. want to be able to use future modules that raise exceptions not defined
  2121. by your program, follow the following guidelines:
  2122.  
  2123. - Use and define ID 0 as "no error" (i.e. normal termination)
  2124.  
  2125. - For exceptions specific to your program, use the ID's 1-10000.
  2126.   Define these in the usual fashion with ENUM:
  2127.  
  2128.   ENUM OK,NOMEM,NOFILE,...
  2129.  
  2130.   (OK will be 0, and others will be 1+)
  2131.  
  2132. - ID's 12336 to 2054847098 (these are all identifiers
  2133.   consisting of upper/lowercase letters and digits of lenght 2,3 or 4
  2134.   enclosed in "") are reserved as common exceptions. A common exception
  2135.   is an exception that need not need be defined in your program, and that
  2136.   may be used by implementors of modules (with functions in them) to
  2137.   raise exceptions: for example, if you design a set of procedures that
  2138.   perform a certain task, you may want to raise exceptions. As you would
  2139.   want to use those functions in various programs, it would be
  2140.   unpractical to have to coordinate the ID's with the main program,
  2141.   furthermore, if you use more than one set of functions (in a module,
  2142.   in the future) and every module would have a different ID for
  2143.   'no memory!', things could get out of hand.
  2144.   This is where common exceptions come in: the common out-of-memory
  2145.   ID is "MEM" (including the quotes): any implementor can now simply
  2146.  
  2147.   Raise("MEM")
  2148.  
  2149.   from all different procedures, and the programmer that uses the module
  2150.   only needs to suply an exception handler that understands "MEM"
  2151.  
  2152.   future modules that contain sets of functions will specify what
  2153.   exception a certain procedure may raise, and if these overlap
  2154.   with the ID's of other procedures, the task of the programmer
  2155.   that has to deal with the exceptions will be greatly simplyfied.
  2156.  
  2157.   examples:
  2158.  
  2159.   (system)
  2160.  
  2161.   "MEM"        out of memory
  2162.   "FLOW"    (nearly) stack overflow
  2163.   "^C"        Control-C break
  2164.   "ARGS"    bad args
  2165.  
  2166.   (exec/libraries)
  2167.  
  2168.   "SIG"        could not allocate signal
  2169.   "PORT"    could not create messageport
  2170.   "LIB"        library not available
  2171.   "ASL"        no asl.library
  2172.   "UTIL"    no utility.library
  2173.   "LOC"        no locale.library
  2174.   "REQ"        no req.library
  2175.   "RT"        no reqtools.library
  2176.   "GT"        no gadtools.library (similar for others)
  2177.  
  2178.   (intuition/gadtools/asl)
  2179.  
  2180.   "WIN"        failed to open window
  2181.   "SCR"        failed to open screen
  2182.   "REQ"        could not open requester
  2183.   "FREQ"    could not open filerequester
  2184.   "GAD"        could not create gadget
  2185.   "MENU"    could not create menu(s)
  2186.  
  2187.   (dos)
  2188.  
  2189.   "OPEN"    could not open a file / file does not exist
  2190.   "OUT"        problems while reading
  2191.   "IN"        problems while writing
  2192.   "EOF"        unexpected end of file
  2193.   "FORM"    input format error
  2194.  
  2195.   The general tendancy is uppercase for general system
  2196.   exceptions, and lowercase (and mixed) for specific modules.
  2197.  
  2198. - all others (including all negative ID's) remain reserved.
  2199.  
  2200.  
  2201. +---------------------------------------------------------------+
  2202. |                      14. OO PROGRAMMING            |
  2203. +---------------------------------------------------------------+
  2204.  
  2205. As this hasn't been implemented yet, it's not documented either.
  2206.  
  2207.  
  2208. +---------------------------------------------------------------+
  2209. |                      15. INLINE ASSEMBLY            |
  2210. +---------------------------------------------------------------+
  2211.  
  2212. 15A. identifier sharing
  2213. -----------------------
  2214. As you've probably guessed from the example in chapter 5D, assembly
  2215. instructions may be freely mixed with E code. The big secret is, that
  2216. a complete assembler has been built in to the compiler.
  2217. Apart from normal assembly addressing modes, you may use the following
  2218. identifiers from E:
  2219.  
  2220. mylabel:
  2221. LEA mylabel(PC),A1        /* labels */
  2222.  
  2223. DEF a                /* variables */
  2224. MOVE.L (A0)+,a            /* note that <var> is <offset>(A4) (or A5) */
  2225.  
  2226. MOVE.L dosbase,A6        /* library call identifiers */
  2227. JSR    Output(A6)
  2228.  
  2229. MOVEQ  #TRUE,D0            /* constants */
  2230.  
  2231.  
  2232. 15B. the inline assembler compared to a macro assembler
  2233. -------------------------------------------------------
  2234. The inline assembler differs somewhat from your average macro-assembler,
  2235. and this is caused mainly by the fact that it is an extension to E,
  2236. and thus it obeys E-syntax. Main differences:
  2237.  
  2238. - comments are with /* */ and not with ";", they have a different meaning.
  2239. - keywords and registers are in uppercase, everything is case sensitive
  2240. - no macros and other luxury assembler stuff (well, there's the complete
  2241.   E language to make up for that ...)
  2242. - You should be aware that registers A4/A5 may not be trashed by inline
  2243.   assembly code, as these are used by E code.
  2244. - no support for LARGE model/reloc-hunks in assembly _YET_.
  2245.   This means practically that you have to use (PC)-relative addressing
  2246.   for now.
  2247.  
  2248.  
  2249. 15C. ways using binary data (INCBIN/CHAR..)
  2250. -------------------------------------------
  2251.  
  2252. INCBIN
  2253.  
  2254. syntax:        INCBIN <filename>
  2255. includes a binary file at the exact spot of the statement, should
  2256. therefore be separate from the code. Example:
  2257.  
  2258. mytab: INCBIN 'df1:data/blabla.bin'
  2259.  
  2260. LONG, INT, CHAR
  2261.  
  2262. syntax:        LONG <values>,...
  2263.         INT <values>,...
  2264.         CHAR <values>,...
  2265. Allows you to place binary data directly in your program. Functions much
  2266. like DC.x in assembly. Note that the CHAR statement also takes strings,
  2267. and will always be aligned to an even word-boundary. Example:
  2268.  
  2269. mydata: LONG 1,2; CHAR 3,4,'hi folks!',0,1
  2270.  
  2271.  
  2272. 15D. OPT ASM
  2273. ------------
  2274. OPT ASM is discussed also in chapter 16A. It allows you to operate
  2275. 'EC' as an assembler. There's no good reason to use EC over some
  2276. macro-assembler, except that it is significantly faster than for example
  2277. A68k, equals DevPac and loses from AsmOne (sob 8-{). You will also have
  2278. a hard time trying to squeeze your disks of old seka-sources through EC,
  2279. because of the differences as described in chapter 15B. If you want to write
  2280. assembly programs with EC, and want to keep your sources compatible with
  2281. other assemblers, simply precede all E-specific elements with a ";",
  2282. EC will use them, and any other assembler will see them as a comment.
  2283. Example:
  2284.  
  2285. ; OPT ASM
  2286.  
  2287. start:    MOVEQ    #1,D0        ; /* do something silly */
  2288.     RTS            ; /* and exit */
  2289.  
  2290. this will be assembled by any assembler, including EC
  2291.  
  2292.  
  2293. +---------------------------------------------------------------+
  2294. |                    16. IMPLEMENTATION ISSUES            |
  2295. +---------------------------------------------------------------+
  2296.  
  2297. 16A. the OPT keyword
  2298. --------------------
  2299.  
  2300. OPT, LARGE, STACK, ASM, NOWARN, DIR, OSVERSION
  2301.  
  2302. syntax:        OPT <options>,...
  2303. allows you to change some compiler settings:
  2304. LARGE        Sets code and data model to large. Default is small;
  2305.         the compiler generates 100% pc-relative code, with a
  2306.         max-size of 32k. With LARGE, there are no such limits,
  2307.         and reloc-hunks are generated. See -l
  2308. STACK=x        Set stacksize to x bytes yourself. Only if you know what
  2309.         you are doing. Normally the compiler makes a very good
  2310.         guess itself at the required stack space.
  2311. ASM        Set the compiler to assembly mode. From there on, only
  2312.         assembly instructions are allowed, and no initialisation
  2313.         code is generated. See: chapter inline assembly
  2314. NOWARN        Shut down warnings. The compiler will warn you if it
  2315.         *thinks* your program is incorrect, but still syntactically
  2316.         ok. See -n
  2317. DIR=moduledir    Sets the directory where the compiler searches for modules.
  2318.         default='emodules:'
  2319. OSVERSION=vers    Default=33 (v1.2). Sets the minimum version of the kickstart
  2320.         (like 37 for v2.04) your program runs on. That way, your
  2321.         program simply fails while the dos.library is being opened
  2322.         in the initialisation code when running on an older machine.
  2323.         However, checking the version yourself and giving an
  2324.         appropriate error-message is more helpful for the user.
  2325. example:
  2326.  
  2327. OPT STACK=20000,NOWARN,DIR='df1:modules',OSVERSION=39
  2328.  
  2329.  
  2330. 16B. small/large model
  2331. ----------------------
  2332. Amiga E lets you choose between SMALL and LARGE code/data model.
  2333. Note that most of the programs you'll write (especially if you just
  2334. started with E) will fit into 32k when compiled: you won't have to
  2335. bother setting some code-generation model. You'll recognise the
  2336. need for LARGE model as soon as EC starts complaining that it can't
  2337. squeeze your code into 32k anymore. To compile a source with LARGE model:
  2338.  
  2339. 1> ec -l sizy.e
  2340.  
  2341. or better yet, put the statement
  2342.  
  2343. OPT LARGE
  2344.  
  2345. in your code.
  2346.  
  2347.  
  2348. 16C. stack organisation
  2349. -----------------------
  2350. To store all local and global variables, the run-time system of an
  2351. executable generated by Amiga E allocates a chunk of memory,
  2352. from which it takes some fixed part to store all global variables.
  2353. The rest will be dynamically used as functions get called.
  2354. as a function is called in E, space on the stack is reserved
  2355. to store all local data, which is released upon exit of the function.
  2356. That is why having large arrays of local data can be dangerous when
  2357. used recursively: all data of previous calls to the same function
  2358. still resides on the stack and eats up large parts of the free stack
  2359. space. However, if PROC's are called in a linear fashion, there's
  2360. no way the stack will overflow.
  2361. Example:
  2362.  
  2363. global data:        10k (arrays e.d)
  2364. local data PROC #1:     1k
  2365. local data PROC #1:     3k
  2366.  
  2367. the runtime system always reserves an extra 10k over this for normal
  2368. recursion (for example with small local-arrays) and additional buffers/
  2369. system spaces, thus will allocate a total of 24k stack space
  2370.  
  2371.  
  2372. 16D. hardcoded limits
  2373. ---------------------
  2374.  
  2375. Note these signs: (+-)    just about, depends on situation,
  2376.                   (n.l.)  no clear limit, but this seems reasonable.
  2377.  
  2378. --------------------------------------------------------------------------
  2379. OBJECT/ITEM                    SIZE/AMOUNT/MAX
  2380. --------------------------------------------------------------------------
  2381.  
  2382. value datatype CHAR                0 .. 255
  2383. value datatype INT                -32 k .. +32 k
  2384. value datatype LONG/PTR                -2 gig .. +2 gig
  2385.  
  2386. identifierlength                100 bytes (n.l.)
  2387. length of one source line            2000 lexical tokens (+-)
  2388. source length                    2 gig (theoretically)
  2389. constant lists                    few hundred elements (+-)
  2390. constant strings                1000 chars (n.l.)
  2391. max. nesting depth of loops (IF, FOR etc.)    500 deep
  2392. max. nesting depth of comments            infinite
  2393.  
  2394. #of local variables per procedure        8000
  2395. #of global variables                7500
  2396. #of arguments to own functions            8000 (together with locals)
  2397. #of arguments to E-varargs functions (WriteF())    64
  2398.  
  2399. one object (allocated local/global or dyn.)    8 k
  2400. one array, list or string (local or global)    32 k
  2401. one string (dynamically)            32 k
  2402. one list (dynamically)                128 k
  2403. one array (dynamically)                2 gig
  2404.  
  2405. local data per procedure            250 meg
  2406. global data                    250 meg
  2407.  
  2408. code size of one procedure            32 k
  2409. code size of executable                32 k SMALL, 2 gig LARGE model
  2410. current practical limit (may extend in future)    2-5 meg
  2411.  
  2412. buffersize of generated code and identifiers    relative to source
  2413. buffersize of labels/branches and intermediate    independently (re)allocated
  2414.  
  2415.  
  2416.  
  2417. 16E. error messages, warnings and the unreferenced check
  2418. --------------------------------------------------------
  2419. Sometimes, when compiling your source with EC, you get a message
  2420. of the sort UNREFERENCED: <ident>, <ident>, ...
  2421. This is the case when you have declared variables, functions or labels,
  2422. but did not use them. This is an extra service rendered to you by the
  2423. compiler to help you find out about those hard to find errors.
  2424.  
  2425. There are several warnings that the compiler issues to notify you that
  2426. something might be wrong, but is not really an error.
  2427.  
  2428.  
  2429. - "A4/A5 used in inline assembly"
  2430.   This is the warning you'll get if you use registers A4 or A5 in your
  2431.   assembly code. The reason for this is that those registers are used
  2432.   internally by E to address the global and local variables respectively.
  2433.   Of course there might be a good reason to use these, like doing
  2434.   a MOVEM.L A4/A5,-(A7) before a large part of inline assembly code
  2435.  
  2436. - "keep an eye on your stacksize"
  2437. - "stack is definitely too small"
  2438.   Both these may be issued when you use OPT STACK=<size>. The compiler
  2439.   will simply match your <size> against its own estimate (see chapter 16C),
  2440.   and issue the former warning if it thinks it's ok but a bit on the small
  2441.   side, and the latter if it's probably too small.
  2442.  
  2443. - 'suspicious use of "=" in void expressions'
  2444.   This warning is issued if you write expressions like 'a=1' as a
  2445.   statement. One reason for this is the fact that a comparison doesn't
  2446.   make much sense as a statement, but the main reason is that it could be
  2447.   an often occurring typo for 'a:=1'. Forgetting those ":" may be hard to
  2448.   find, and it may have disastrous consequences.
  2449.  
  2450. Errors.
  2451.  
  2452. - 'syntax error'
  2453.   Most common error. This error is issued either when no other
  2454.   error is appropriate or your way of ordering code in your sources
  2455.   is too abnormal.
  2456.  
  2457. - 'unknown keyword/const'
  2458.   You have used an identifier in uppercase (like "IF" or "TRUE"), and
  2459.   the compiler could not find a definition for it. Causes:
  2460.   * mispelled keyword
  2461.   * you used a constant, but forgot to define it in a CONST statement
  2462.   * you forgot to specify the module where your constant is defined
  2463.  
  2464. - '":=" expected'
  2465.   You have written a FOR statement or an assignment, and put something
  2466.   other than ":=" in its place.
  2467.  
  2468. - 'unexpected characters in line'
  2469.   You used characters that have no syntactic meaning in E outside of
  2470.   a string. examples: "@!&\~"
  2471.  
  2472. - 'label expected'
  2473.   At some places, for example after the PROC or JUMP keyword,
  2474.   a label identifier is required. You wrote something else.
  2475.  
  2476. - '"," expected'
  2477.   In specifying a list of items (for example a parameter list)
  2478.   you wrote something else instead of a comma.
  2479.  
  2480. - 'variable expected'
  2481.   This construction requires a variable, example:
  2482.   FOR <var>:= ... etc.
  2483.  
  2484. - 'value does not fit in 32 bit'
  2485.   In specifying a constant value (see chapter 2A-2E) you wrote too
  2486.   large a number, examples:  $FFFFFFFFF, "abcdef".
  2487.   Also occurs when you define a SET of more than 32 elements.
  2488.  
  2489. - 'missing apostrophe/quote'
  2490.   You forgot the ' at the other end of a string.
  2491.  
  2492. - 'incoherent program structure'
  2493.   * you started a new PROC before ending the last one
  2494.   * you don't nest your loops properly, for example:
  2495.     FOR
  2496.       IF
  2497.       ENDFOR
  2498.     ENDIF
  2499.  
  2500. - 'illegal command-line option'
  2501.   In specifying 'EC -opt source' you wrote something for '-opt'
  2502.   that is not a legal option to EC.
  2503.  
  2504. - 'division and multiplication 16bit only'
  2505.   The compiler detected that you were about to use 32bits
  2506.   for * or /. This would not have the desired result at runtime.
  2507.   See Mul() and Div().
  2508.  
  2509. - 'superfluous items in expression/statement'
  2510.   After the compiler already compiled your statement, it still found
  2511.   lexical tokens instead of an end of line. You probably forgot
  2512.   the <lf> or ";" to separate two statements.
  2513.  
  2514. - 'procedure "main" not available'
  2515.   Your program does not include a main procedure !
  2516.  
  2517. - 'double declaration of label'
  2518.   You declared a label twice, for example:
  2519.   label:
  2520.   PROC label()
  2521.  
  2522. - 'unsafe use of "*" or "/"'
  2523.   This again has to do with 16bit instead of 32bit * and /.
  2524.   See 'division and multiplication 16bit only'.
  2525.  
  2526. - "reading sourcefile didn't succeed"
  2527.   Check your source spec. that you gave with 'ec mysource'
  2528.   make sure the file ends in '.e', and your command line doesn't.
  2529.  
  2530. - "writing executable didn't succeed"
  2531.   Trying to write the generated code as an executable caused a dos
  2532.   error. For example, the executable that did already exist could
  2533.   not be overwritten.
  2534.  
  2535. - 'no args'
  2536.   "USAGE: ec [-opts] <sourcecodefilename> (`.e' is added)"
  2537.   You get this by just typing 'ec' without any arguments.
  2538.  
  2539. - 'unknown/illegal addressing mode'
  2540.   This error is reported only by the inline assembler. Possible causes are:
  2541.   * you used some addressing mode that does not exist on the 68000
  2542.   * the addressing mode exists, but not for this instruction.
  2543.     not all assembly instructions support all combinations of
  2544.     effective addresses for source and destination.
  2545.  
  2546. - 'unmatched parentheses'
  2547.   Your statement has more "(" than ")" or the other way around
  2548.  
  2549. - 'double declaration'
  2550.   One identifier is used in two or more declarations.
  2551.  
  2552. - 'unknown identifier'
  2553.   An identifier is not used in any declaration; it is unknown.
  2554.   You probably forgot to put it in a DEF statement.
  2555.  
  2556. - 'incorrect #of args or use of ()'
  2557.   * You forgot to put "(" or ")" at the right spot
  2558.   * you supplied the incorrect #of arguments to some function
  2559.  
  2560. - 'unknown e/library function'
  2561.   You wrote an identifier with the first character in uppercase, and
  2562.   the second in lowercase, but the compiler could not find a definition.
  2563.   Possible causes:
  2564.   * Misspelled name of function
  2565.   * You forgot to include the module that defines this library call.
  2566.  
  2567. - 'illegal function call'
  2568.   Rarely occurs. You get this one if you try to construct weird
  2569.   function calls like nested WriteF()'s. Example:
  2570.   WriteF(WriteF('hi!'))
  2571.  
  2572. - 'unknown format code following "\"'
  2573.   You specified a format code in a string which is illegal.
  2574.   See chapter 2F for a listing of format codes
  2575.  
  2576. - '/* not properly nested comment structure */'
  2577.   The #of '/*' is unequal to the #of '*/', or is placed in a funny order.
  2578.  
  2579. - 'could not load binary'
  2580.   <filespec> in INCBIN <filespec> could not be read.
  2581.  
  2582. - '"}" expected'
  2583.   You started an expression with "{<var>" , but forgot the "}"
  2584.  
  2585. - 'immediate value expected'
  2586.   Some constructions require an immediate value instead of an expression.
  2587.   Example:
  2588.   DEF s[x*y]:STRING   /* wrong: only something like s[100]:STRING is legal */
  2589.  
  2590. - 'incorrect size of value'
  2591.   You specified an unacceptably large (or small) value for some construction.
  2592.   Examples:
  2593.   DEF s[-1]:STRING, t[1000000]:STRING    /* needs to be 0..32000  */
  2594.   MOVEQ #1000,D2                         /* needs to be -128..127 */
  2595.  
  2596. - 'no e code allowed in assembly modus'
  2597.   You wish to operate the compiler as an assembler by writing 'OPT ASM',
  2598.   but, by accident, wrote some E code.
  2599.  
  2600. - 'illegal/inappropriate type'
  2601.   At someplace where a <type> spec. was needed, you wrote something
  2602.   inappropriate. Examples:
  2603.   DEF a:PTR TO ARRAY       /* no such type */
  2604.   [1,2,3]:STRING
  2605.  
  2606. - '"]" expected'
  2607.   You started with "[", but never ended with "]"
  2608.  
  2609. - 'statement out of local/global scope'
  2610.   A breakpoint of scope is the first PROC statement. before that,
  2611.   only global definitions (DEF,CONST,MODULE etc.) are allowed, and no code.
  2612.   In the second part, only code and function definitions are legal, no
  2613.   global definitions.
  2614.  
  2615. - 'could not read module correctly'
  2616.   A dos error occurred while trying to read a module from a MODULE
  2617.   statement. Causes:
  2618.   * emodules: was not assigned properly
  2619.   * module name was misspelled, or did not exist in the first place
  2620.   * you wrote MODULE 'bla.m' instead of MODULE 'bla'
  2621.  
  2622. - 'workspace full!'
  2623.   Rarely occurs. If it does, you'll need the '-m' option to manually
  2624.   force EC to make a bigger estimate on the needed amount of memory.
  2625.   Try compiling with -m2, then -m3 until the error disappears.
  2626.   You'll probably be writing huge applications with giant amounts
  2627.   of data just to even possibly get this error.
  2628.  
  2629. - 'not enough memory while (re-)allocating'
  2630.   Just like that. Possible solutions:
  2631.   1. You were running other programs in multitasking. Leave them and try again.
  2632.   2. You were low on memory anyway and your memory was fragmented.
  2633.      Try rebooting.
  2634.   3. None of 1-2. Buy a memory expansion (ahum).
  2635.  
  2636. - 'incorrect object definition'
  2637.   You were being silly while writing the definitions between OBJECT and
  2638.   ENDOBJECT. See chapter 8F to find out how to do it right.
  2639.  
  2640. - 'illegal use of/reference to object'
  2641.   If you use expressions like ptr.member, member needs to be a legal
  2642.   member of the object ptr is pointing to.
  2643.  
  2644. - 'incomplete if-then-else expression'
  2645.   If you use IF as an operator (see chapter 4E), then an ELSE part
  2646.   needs to be present: an expression with an IF in it always needs to
  2647.   return a value, while a statement with an IF in it can just 'do nothing'
  2648.   if no ELSE part is present.
  2649.  
  2650. - 'unknown object identifier'
  2651.   You used an identifier that was recognised by the compiler as being
  2652.   part of some object, but you forgot to declare it. Causes:
  2653.   * misspelled name
  2654.   * missing module
  2655.   * the identifier in the module is spelled not like you expected
  2656.     from the RKRM's. Check with ShowModule.
  2657.     Note that amiga-system-objects inherit from assembly identifiers,
  2658.     not from C. Second: identifiers obey E-syntax.
  2659.  
  2660. - 'double declaration of object identifier'
  2661.   One identifier used in two object definitions
  2662.  
  2663. - 'reference(s) out of 32k range: switch to LARGE model'
  2664.   Your program is growing larger than 32k. Simply put 'OPT LARGE'
  2665.   in your source and code on. See Chapter 16B.
  2666.  
  2667. - 'reference(s) out of 256 byte range'
  2668.   You probably wrote BRA.S or Bcc.S over too great a distance.
  2669.  
  2670. - 'too sizy expression'
  2671.   You used a list [], possibly recursive [[]], that is too sizy.
  2672.  
  2673. - 'incomplete exception handler definition'
  2674.   You probably used EXCEPT without HANDLE, or the other way round
  2675.   see chapter 13 on exception handling.
  2676.  
  2677.  
  2678. 16F. compiler buffer organisation and allocation
  2679. ------------------------------------------------
  2680. When you get the error 'workspace full' (very unlikely), or want
  2681. to know what really happens when your program is compiled, it's useful
  2682. to know how EC organises its buffers.
  2683.  
  2684. A compiler, and in this case EC needs buffers to keep track of all sorts
  2685. of things, like identifiers etc., and it needs a buffer to keep the
  2686. generated code in. EC doesn't know how big these buffers need to be.
  2687. for some buffers, like the one for storing constants, this is no
  2688. problem: if the buffer is full while compiling, EC just allocates a
  2689. new piece of memory and continues. Other buffers, like the one for
  2690. the generated code, need to be a continuous block of memory that doesn't
  2691. move while compiling: EC needs to make a pretty good estimate of
  2692. this buffersize to be able to compile small and large sources alike.
  2693. To do this, EC computes the needed memory relative to the size of
  2694. your source code, and adds a nice amount to it. This way, in 99% of the
  2695. cases, EC will have allocated enough memory to compile just about any
  2696. source, in other cases, you'll get the error and have to specify more
  2697. memory with the '-m' option.
  2698.  
  2699. Experiment with different types and sizes of example-sources in combination
  2700. with the '-b' option to see how this works in practice.
  2701.  
  2702.  
  2703. 16G. a small history
  2704. --------------------
  2705. E is not 'just another language': it was carefully and gradually designed by
  2706. the author of the compiler because he was not too happy with existing
  2707. programming languages, and specifically not the sluggish-code-generating
  2708. and slow compilers that were written for them. Amiga E had as primary
  2709. goal to be used as language for the author to program his amiga programs
  2710. in, and he has succeeded in doing so by far. E was developed intensively
  2711. over the course of 1.5 years and was certainly not the first compiler
  2712. written by the author: some of you may remember the DEX compiler.
  2713.  
  2714. This one was slow and unpowerful and is hardly something that can be
  2715. compared to a compiler like Amiga E, but certainly gave the author some
  2716. useful experience to be able to make Amiga E what it is today.
  2717. DEX programmers will notice that it is very easy to convert their old
  2718. DEX sources to E, and continue developing with 10x the power at 20x the
  2719. speed. A funny thing about DEX and E is that the development of the
  2720. two compilers did overlap: while DEX was done, E was halfway v1.6.
  2721. Because E was already much better back then, E libraries/examples and
  2722. code were transferred to DEX by popular demand, so the predecessor
  2723. inherited features from its successor.
  2724. The author also wrote numerous other compilers and interpreters, some
  2725. of which were never distributed in any way.
  2726.  
  2727. Amiga E is a product that will continue to be developed towards the ultimate
  2728. language / amiga development system:
  2729. - by implementing those missing parts in the language definition
  2730.   * Object Orientedness
  2731.   * better float concept
  2732. - by making compiler specific enhancements
  2733.   * possible 020/030/881 code generation
  2734.   * optimizing the compilation-process, thus possibly doubling the
  2735.     line/minute figures as in compiler.doc
  2736.   * enabling the user to compile own code to modules, and thus develop large
  2737.     applications in a more modular fashion
  2738. - by adding valuable elements to the distribution
  2739.   * an integrated editor ?
  2740.   * source-level debugger ?
  2741.   * CASE tools, for example
  2742. - by fixing bugs (what bugs!?!) 8*-)
  2743.  
  2744.  
  2745. The END! phew! Have fun with E!
  2746.